XML Parsing help

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
boolseye
Participant
Posts: 18
Joined: Mon Jul 15, 2013 4:01 am

XML Parsing help

Post 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
-----------------
Thanks
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post 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
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
boolseye
Participant
Posts: 18
Joined: Mon Jul 15, 2013 4:01 am

Re: XML Parsing help

Post 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
-----------------
Thanks
Post Reply