Page 1 of 1

XML Parsing help

Posted: Thu Dec 03, 2015 2:31 am
by boolseye
need some help on below sample xml

I need to parse an xml and get specific value from repeating element where type is specific.

For example
<ID>123
<SubGroup> <Type>X</Type> <Value>0.0</Value></SubGroup>
<SubGroup> <Type>Y</Type> <Value>1.0</Value></SubGroup>
<SubGroup> <Type>K</Type> <Value>0.0</Value></SubGroup>
</ID>
<ID>456
<SubGroup> <Type>J</Type> <Value>0.0</Value></SubGroup>
<SubGroup> <Type>Z</Type> <Value>0.0</Value></SubGroup>
<SubGroup> <Type>Y</Type> <Value>2.0</Value></SubGroup>
</ID>
================

I'm interested in value of element subgroup where type is "Y"

Output should be like
ID|SubGroupValue
123|1.0
456|2.0

I'm trying to do this using xml stage. Thanks in advance

Posted: Thu Dec 03, 2015 5:15 am
by eostic
XML Stage, or XMLInput Stage?

Either way, your lowest level repeating node is SubGroup. First objective will be to get each SubGroup out as a "row".

If this is xmlInput Stage, then you would make "Type" your repetition element and mark it as a "key"; if this is the xml or hierarchical Stage, then the blue "list" that represents the SubGroup node is the first thing you should drag onto your output link at the mapping page.

You should get six rows in this example, with three columns. Work on that first.

Then use a normal constraint downstream to filter for the types that you want.

Ernie

Re: XML Parsing help

Posted: Tue Dec 08, 2015 9:27 am
by boolseye
Hi eostic,

Thanks for reply.
I was not able to read your answer since it was premium content.

I was able to achieve the goal using xml stage and switch step.

http://www.ibm.com/developerworks/data/ ... index.html

Thanks