Answer :
- retrieve the exact XML path as per the corresponding embedded schema
- iterate over the received XMLList, providing this path filter
Details :
Step #1 : consider the following XML tree, containing a block of <objInst> nodes to be mapped into corresponding Java business instances :
<root>
<tag1>tag1_value</tag1>
<tag2>tag2_value</tag2>
<config>
<tag3>tag3_value</tag3>
<tag4>tag4_value</tag4>
<dir>
<objInst>
<tag1_obj>tag1_obj1_value</tag1_obj>
<tag2_obj>tag1_obj1_value</tag2_obj>
<tag3_obj>tag1_obj1_value</tag3_obj>
<objInst>
<objInst>
<tag1_obj>tag1_obj2_value</tag1_obj>
<tag2_obj>tag1_obj2_value</tag2_obj>
<tag3_obj>tag1_obj2_value</tag3_obj>
<objInst>
<objInst>
<tag1_obj>tag1_obj3_value</tag1_obj>
<tag2_obj>tag1_obj3_value</tag2_obj>
<tag3_obj>tag1_obj3_value</tag3_obj>
<objInst>
</dir>
</config>
<tag5>tag5_value</tag5>
</root>
Step #2 : upon receipt of the HTTPService ResultEvent (event below), here is the easiest/safest way to iterate over the received XMLList :
try
{
for each (var objInst:XML in new XML(event.result.config.dir).elements())
{
// accessing objInst tag1 value simply via : objInst.tag1_obj
// accessing objInst tag2 value simply via : objInst.tag2_obj
// accessing objInst tag2 value simply via : objInst.tag3_obj
// ...
}
}
catch (e:Error)
{
// In case the XML response is not properly formatted
}
Nota: the <root> XML node must be omitted in the above 'event.result.config.dir' notation, since 'event.result' already corresponds to the <root> node of the downloaded XML document.





No comments:
Post a Comment