D attendee_type...
D DS qualified template
D name 20a varying
D phone 4s 0
D meeting DS qualified
D location 20a varying
D attendee likeds(attendee_type)
D dim(100)
D numAttendee...
D 10i 0
D email DS qualified
D to 40a varying
D cc 40a varying
D from 40a varying
D countCc 5i 0
D subject 100a varying
D countSubject 5i 0
D body 1000a varying
D order1 DS qualified
D numpart 10i 0
D part 20a varying dim(100)
D order2 DS qualified
D numpart 10i 0
D part 20a varying dim(100)
D countpart 10i 0
<meeting>
<location>Room 7a</location>
<attendee name="Jim" phone="1234"/>
<attendee name="Mary" phone="2345"/>
<attendee name="Abel" phone="6213"/>
</meeting>
The XML-INTO operation sets countprefix subfield numAttendee to 3, the number of attendee subfields set by the operation. It is not necessary to specify option allowmissing=yes, because the presence of the countprefix subfield for array attendee implicitly allows missing XML data for that particular array.
xml-into meeting %xml('meeting123.xml'
: 'doc=file countprefix=num');
// meeting.attendee(1): name='Jim' phone=1234
// meeting.attendee(2): name='Mary' phone=2345
// meeting.attendee(3): name='Abel' phone=6213
// meeting.numAttendee = 3 for i = 1 to meeting.numAttendee;
if meeting.attendee(i) ...
endfor;
The XML-INTO operation fails because there is insufficient XML data for array attendee, and there is no XML data at all for numAttendee.
xml-into(e) meeting %xml('meeting123.xml'
: 'doc=file');
// %error = *on
<email to="jack@anywhere.com" from="jill@anywhere.com">
<subject>The hill</subject>
<body>How are you feeling after your fall?</body>
</email>
The countprefix=count option is specified, indicating that the prefix for the countprefix subfields is count.
The XML-INTO operation is successful even though there is no XML data for the cc subfield, because the countprefix subfield countCc is available to receive the information that the cc subfield did not get set from the XML.
xml-into email %xml('email456.xml'
: 'doc=file countprefix=count');
// email.to = 'jack@anywhere.com'
// email.from = 'jill@anywhere.com'
// email.cc = ?? (not set by XML-INTO)
// email.countCc = 0
// email.subject = 'The hill'
// email.countSubject = 1
// email.body = 'How are you feeling after your fall?'
if email.countCc = 1;
cc = email.cc;
else;
cc = '';
endif;
if email.countSubject = 1;
subj = email.subject;
else;
subj = "NO SUBJECT";
endif;
<order numpart="2">
<part>hammer</part>
<part>saw</part>
</order>
The XML document contains an attribute numpart that indicates how many part elements there are in the document.
The XML-INTO operation fails. Subfield numpart is a countprefix subfield, so it cannot be explicitly set by the XML-INTO operation.
xml-into(e) order1 %xml('order789.xml'
: 'doc=file countprefix=num path=order');
// %error is set on
The XML-INTO operation succeeds. Subfield numpart is set to 2 from the XML document, and subfield countpart is set to 2 by the countprefix processing. The part array is counted by the countprefix option, so it is not an error that there is insufficient XML data to set the entire array.
xml-into order2 %xml('order789.xml'
: 'doc=file countprefix=count path=order');
// order2.numpart = 2
// order2.part(1) = 'hammer'
// order2.part(2) = 'saw'
// order2.countpart = 2
