Processing an XML file with occurrences

Hello, does anybody have an example of processsing an XML file with occurrences? The file I have to process has the following structure:
Root_element (Element1, Element2)
Element1 (Element11, Element12)
Element11 (#PCDATA)
Element12 (#PCDATA)
Element2 (Element21+)
Element21 (Element211, Element212+)
Element211 (#PCDATA)
Element212 (Element2121, Element2122)
Element2121 (#PCDATA)
Element2122 (#PCDATA)

As you can see in the structure above there are occurrences at Element21 and also at Element212.

I have used the XML2NAT utility to generate parser and serialization for the structure, but I need to read this info into Natural variables.

Thanks in advance for your help.

Couldn’t this be done using structures? i.e.
01 Root_Element
02 Element1
03 Element11 (A) Dynamic
03 Element12 (A) Dynamic
02 Element2 (1:)
03 Element21
04 Element211 (A) Dynamic
04 Element212 (1:
)
05 Element2121 (A) Dynamic
06 Element2122 (A) Dynamic
or something like that? I didn’t try it…:wink:

I am trying that way, problem is that I am not acquainted as of how to get the occurrences of each of the elements at execution time. I have found some info on that and will try. There should be occurrence values coming to Natural after parsing the document … at least that is what I understood from documentation.

You can use the XML Toolkit (can be found at library SYSEXXT, run XML2NAT).
If you specify a DTD for your XML:

<!ELEMENT Root_element (Element1, Element2)> 
<!ELEMENT Element1     (Element11,  Element12)>
<!ELEMENT Element11    (#PCDATA)>
<!ELEMENT Element12    (#PCDATA)>
<!ELEMENT Element2     (Element21+)>
<!ELEMENT Element21    (Element211,  Element212+)>
<!ELEMENT Element211   (#PCDATA)>
<!ELEMENT Element212   (Element2121, Element2122)>
<!ELEMENT Element2121  (#PCDATA)>
<!ELEMENT Element2122  (#PCDATA)>

save to a file with extension .dtd and run the xmltoolkit,
you will get a PDA like this (e.g. for NAT61 using X-Arrays and (A) DYNAMIC):

DEFINE DATA PARAMETER
/* XML: Root_element -> NAT: Root_element
 1 ROOT_ELEMENT /*SEQ
 2 ELEMENT1 /*SEQ
 3 ELEMENT11 (A) DYNAMIC /*PCDATA
 3 ELEMENT12 (A) DYNAMIC /*PCDATA
 2 ELEMENT2 /*SEQ
 3 C@ELEMENT21 (I4)
 3 ELEMENT21 (1:*) /*SEQ
 4 ELEMENT211 (A) DYNAMIC /*PCDATA
 4 C@ELEMENT212 (I4)
 4 ELEMENT212 (1:*) /*SEQ
 5 ELEMENT2121 (A) DYNAMIC /*PCDATA
 5 ELEMENT2122 (A) DYNAMIC /*PCDATA
END-DEFINE

:idea: The counter variables C@ are necessary, because for each multiple elements can have different number of occurrences, but the data space has to be expanded to the maximum value to be saved.

:arrow: Depending on the platform and Natural version and plattform you use, a specific PDA for your datastructure, an implemtation for parsing and serialisation is generated.