XPATH issues while creating a XML file from a text file

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
tradersjoe57
Premium Member
Premium Member
Posts: 13
Joined: Mon Oct 24, 2016 7:03 am

XPATH issues while creating a XML file from a text file

Post by tradersjoe57 »

I have to generate a XML file as below by reading the values from a text file

Text File:(Some delimited file)

Code: Select all

123|John
XML file to generate:

Code: Select all

<Member>
<Person Type="ID">123</Person>
<Person Type="Name">John</Person>
</Member>
XPATH I am using in XML Output stage for respective columns:

For writing the value for attribute value ID

Code: Select all

/Member/Person[@Type="ID"]
For writing the value for attribute value Name

Code: Select all

/Member/Person[@Type="Name"]
But in the output, I am getting the XML file as

Code: Select all

<Member>
<Person Type="ID">
123
John
</Person>
<Member>
Attribute value "Name" is missing.

My job design is simple

SEQ Stage -> XML Output Stage

Any help is much appreciated
Last edited by tradersjoe57 on Mon Oct 24, 2016 11:32 am, edited 1 time in total.
tradersjoe57
Premium Member
Premium Member
Posts: 13
Joined: Mon Oct 24, 2016 7:03 am

Post by tradersjoe57 »

I haven't used XML Transformer stage, Just figured out it might be bale to achieve using that. Will try that out!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

XML is XML so that choice of stage shouldn't really matter.
-craig

"You can never have too many knives" -- Logan Nine Fingers
tradersjoe57
Premium Member
Premium Member
Posts: 13
Joined: Mon Oct 24, 2016 7:03 am

Post by tradersjoe57 »

But just by using a XML Output stage, writing different attributes values for the same element is resulting in the output mentioned in the question. How many ever attributes I have, its defaulting the first one and then rest of the values are written underneath it

Code: Select all

<Member>
<Person Type="ID">
123
John
</Person>
<Member> 
Instead of

Code: Select all

<Member>
<Person Type="ID">123</Person>
<Person Type="Name">John</Person>
<Member>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Which is more about the settings you are using in the stage rather than the choice of stage. Can you detail those, please?

Or maybe Ernie already has enough information here to help. Me, I'm just trying to set the table, he's the one that bats cleanup here. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
tradersjoe57
Premium Member
Premium Member
Posts: 13
Joined: Mon Oct 24, 2016 7:03 am

Post by tradersjoe57 »

I have a Row Generator and then a XML Output stage

ROW_GENERATOR Stage -----> XML Output Stage

In the Row Generator, I have the below two fields

Code: Select all

ID: Integer->Description Field:         /Member/Person[@Type="ID"]
Name: Varchar -> Description Field:     /Member/Person[@Type="Name"]
Next, XML Output Stage:

1)Stage->Document Settings : Nothing is selected
2)Stage->Transformation Settings:
->Output mode:Aggregate all rows is selected
->element style: Single tag
3)Stage->Options
Writing to output file
Indentation: Space
New Line: DOS
Encoding:UTF-8

AND then in the Input tab,

I have the same column names as Row generator with the same description.
tradersjoe57
Premium Member
Premium Member
Posts: 13
Joined: Mon Oct 24, 2016 7:03 am

Post by tradersjoe57 »

Any thoughts?
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...been swamped at our user conference. Craig....thx for the nod! :)

This is one of those ugly and poorly designed xmls. A person whole node with sub elements of type and name would have been nicer.

Person is two indpendent elements in your example....a "repeating node". You can do what you need but first have to get those two columns onto their own Rows........ 2 elements......2 rows.......

There is more to it than that, but goal number one is to first learn how to do a pivot.....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply