An example on processing your xml.
h DFTACTGRP(*NO) ACTGRP(*CALLER)
h OPTION(*NODEBUGIO)
*--------------------------------------------------------------------
* XML tables
*--------------------------------------------------------------------
dcl-ds request qualified;
order likeds(t_order) dim(05); // max 5 orders
num_order int(10);
end-ds;
dcl-ds t_order qualified template;
nbr char(10);
item_list likeds(t_item_list);
num_item_list int(10);
end-ds;
dcl-ds t_item_list qualified template;
item char(15) dim(10); // max 10 items
num_item int(10);
end-ds;
d xmlstring s 2048A Varying
d xmlfile s 256A Varying
d xmloptions s 100A Varying
d idxorder s 5u 0
d idxitem s 5u 0
/free
exsr @Importxml;
*inlr = *on;
return;
begsr @Importxml;
xmloptions = 'doc=string +
case=any ns=remove +
allowextra=no allowmissing=yes +
countprefix=num_ +
path=request';
// use xmlfile and doc=file when input is from a stmf
xmlfile = '/somedir/somefile.xml';
xmlstring = '<request> +
<order> +
<nbr>123</nbr> +
<item_list> +
<item>abc</item> +
<item>def</item> +
</item_list> +
</order> +
<order> +
<nbr>456</nbr> +
<item_list> +
<item>abc</item> +
<item>def</item> +
<item>xyz</item> +
</item_list> +
</order> +
</request>';
clear request;
monitor;
Xml-Into request %xml(xmlstring : xmloptions);
on-error;
endMon;
for idxorder = 1 to request.num_order;
dsply request.order(idxorder).nbr;
if request.order(idxorder).num_item_list <> *zero;
for idxitem = 1 to request.order(idxorder)
.item_list
.num_item;
dsply request.order(idxorder)
.item_list
.item(idxitem);
endfor;
endif;
endfor;
endsr;
-----Oprindelig meddelelse-----
Fra: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] På vegne af Moses Nang
Sendt: 8. maj 2014 22:42
Til: web400@xxxxxxxxxxxx
Emne: [WEB400] XML-INTO Example
Hello,
I'm fairly new to using xml-into. I'm currently trying to write a program
that uses xml-into and %handler to parse order information. How can I use
xml-into and %handler to parse the xml and write them into separate header
and detail tables without having to specify the order nbr inside of the
item_list section. Anyone have an example I can check out? Below is a
watered down sample xml I need to parse:
<request>
<order>
<nbr>123</nbr>
<item_list>
<item>abc</item>
<item>def</item>
</item_list>
</order>
<order>
<nbr>456</nbr>
<item_list>
<item>abc</item>
<item>def</item>
<item>xyz></item>
</item_list>
</order>
</request>
Thanks,
Moses Nang
Integrated Merchandising Systems
(847) 583-7112
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing
list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/web400.
As an Amazon Associate we earn from qualifying purchases.