read-xml() without relation fields

Posted by ioanadan on 12-Sep-2016 08:22

Is it possible to import data into dataset from an xml with read-xml when there are no fields available in the xml for relation between temp-tables? or the only way is to parse the xml and generate the id's for the relation fields manually as walking through the xml hierarchy

All Replies

Posted by Brian K. Maher on 12-Sep-2016 08:28

You may need to manually add id values, however, the best thing to do is to read the xml file into a dynamic dataset then do a write-xml and dump it right back out to a file and see what results you get.  write-xml may be able to infer a relationship from the xml itself but the only way to know for sure is to read it in and write it out.

Posted by Peter Judge on 12-Sep-2016 08:32

You can use the PARENT-ID-RELATION depending on version. Check out the doc for more.
PARENT-ID-RELATION [ data-rel-name ] FOR parent-id-rel-spec
Specifies that:
·         The relationship between the parent and child buffer is based on the RECID of the parent record when reading from or writing to an XML document or JSON string.
·         The child rows of a ProDataSet buffer are nested within their parent rows when the ProDataSet data or schema is rendered to an XML document or JSON string.
·         The child RECID field is not serialized.

Posted by on 12-Sep-2016 09:20

If you define the relations as nested there is no need to have parent’s pk fields in child table, do you have the dataset definition upfront or need to infer that from the XML data?


    FIELD pid    AS CHAR
    FIELD id     AS CHAR.

DEFINE DATASET ds SERIALIZE-NAME 'info' FOR ttparent, ttchild DATA-RELATION FOR ttparent, ttchild RELATION-FIELDS(pid, pid) NESTED.

DEFINE VARIABLE lchar AS LONGCHAR INITIAL '<info><process><pid>123</pid><task><id>1</id></task><task><id>2</id></task></process><process><pid>8080</pid><task><id>hello</id></task><task><id>world</id></task></process></info>'.

DATASET ds:READ-XML('longchar', lchar, 'empty', ?, TRUE).

FOR EACH ttparent:
    DISPLAY ttparent.

    FOR EACH ttchild WHERE =
        DISPLAY ttchild.

Marian Edu

Acorn IT 
+40 740 036 212

This thread is closed