Using XSD to generate ProDataSet, populate manually, then use ProDataSet to create XML

90 Views Asked by At

I have recently discovered the ProDataSet and the things it can do with XML. At a high level, I'm trying to use a 3rd party XSD document to dynamically create a ProDataSet via READ-XMLSCHEMA, populate that ProDataSet, and then use WRITE-XML to dump that data back out into a structured XML file, using the relationships and attributes imported in the first step. This would be a huge time saver if all I have to do is map my internal data to the ProDataSet and let it handle the XML generation.

The problem I'm encountering is that my actual DB structure is nothing close to the structure defined in the XSD. Table names, field names, relationships, etc. are all different. In theory, it would be fairly simple to use my internal data to manually populate the ProDataSet, but I cannot seem to get this "mapping" portion to work and I'm starting to think my main concept isn't possible.

I feel like I've tried everything, but my latest iteration is using the imported ProDataSet to dynamically create temp tables with the exact same structure using ADD-LIKE-FIELD. I'm able to then manually create temp table records with BUFFER-CREATE and can map my internal DB to the ProDataSet structure. In theory, I'm able to define the ProDataSet sources with ADD-SOURCE-BUFFER and ATTACH-DATA-SOURCE, but the relationships are not carrying over with FILL() and dumping the XML only outputs the parent element without any of the child records. I'm not sure I'd like to focus on this solution, as I feel like it's the long way around the block, but it is my most successful thus far.

  1. Am I barking up the wrong tree?
  2. If not, does anyone have a top-to-bottom example of doing something like this? I've been trying to piece together the concepts from various sources, but I cannot find anything that is comprehensive. Every example is working on the premise that the ProDataSet mimics your existing DB structure (which I understand).
2

There are 2 best solutions below

0
Stefan Drissen On

I have never tried using the read-xmlschema as a starting point, but manually crafting datasets with relations and a sprinkling of serialize-name attributes should work.

Maybe see How to export XML in progress? as a starting point (I realize this is the other way around) - or provide a tangible snippet.

I am guessing that you have read Converting a ProDataset to XML and back - basic guidelines?

0
nwahmaet On

The problem I'm encountering is that my actual DB structure is nothing close to the structure defined in the XSD. Table names, field names, relationships, etc. are all different. In theory, it would be fairly simple to use my internal data to manually populate the ProDataSet, but I cannot seem to get this "mapping" portion to work and I'm starting to think my main concept isn't possible.

The mapping between temp-table fields (schema) and the database schema is done using the ATTACH-DATA-SOURCE statement and the related DATA-SOURCE query. Look at this doc which has links to both concepts. The query is a standard ABL query and can read from 1 or more tables. This is the mechanism you use to associate database tables to temp-tables in a ProDataSet. The ATTACH-DATA-SOURCE function lets you map fields in the temp-table to fields in the database tables that are in the query. This assumes that the datatypes are the same for the temp-table and db fields (if not, there are callbacks you can use to modify/convert data).

You can attach the DATA-SOURCE only when you need to read (populate) the temp-table(s) in the dataset, or when you need to write data to the database tables.