One Star

[XML] Reading nested NodeSets / NodeLists

Greetings!
I have run into a bit of a dead-end with reading XML. I can use tExtractXMLField to parse an XML file via XPath, but I cannot think of how to parse said XML when there are multiple nested node lists.
Easier illustrated via an example:
<database>
<people>
<person>
<name>John</name>
<child>Billy</child>
<child>Bobby</child>
<child>Samantha</child>
</person>
<person>
<name>Maria</name>
<child>Kyle</child>
<child>Michael</child>
<person>
<name>Steven</name>
<child>Stephanie</child>
<child>Joanne</child>
</person>
</people>
</database>

In the above case, the NodeSet of <person> has an "XPath Loop Query" (within Talend) of "/database/people/person". Within that NodeSet, we have XPath "./name" for <name> and "./child" for another NodeSet of <child>. Assuming there was just one child, one could simply use tExtractXMLField set up ala:
XPath Loop Query: /database/people/person
Column | XPath
Name | ./name
Child | ./child
./child is a NodeSet however, and I imagine simply calling ./child will return the first (or the last?) one only. I need to figure out how to, given the above mock XML, end up with an array of pairs (personName,child) for every child. I am currently exploring the 'Get Nodes' option, but I cannot seem to find any concrete docs that would allow me to solve the above situation.
Any help would be greatly appreciated!
3 REPLIES
One Star

Re: [XML] Reading nested NodeSets / NodeLists

Hi,
Try starting with child rather than person. A child's always going to have a parent person and probably a name, so that's the most reliable driver. See this blog post that recommends analyzing the XML from the bottom up (rather than top down).
http://bekwam.blogspot.com/2011/07/xpath-loops-in-talend-open-studio.html
One Star

Re: [XML] Reading nested NodeSets / NodeLists

I am really impressed with your writing skills as well as with the layout on your weblog. bodybuilding supplements Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it?s rare to see a nice blog like this one these days..

Re: [XML] Reading nested NodeSets / NodeLists

For detailed explanation of reading and processing XML file with multiple nested loops visit the blog post
http://vikramtakkar.com/2013/02/read-xml-having-multiple-nested-loops.html