Page 1 of 1

XPATH issues while creating a XML file from a text file

Posted: Mon Oct 24, 2016 7:09 am
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

Posted: Mon Oct 24, 2016 9:55 am
by tradersjoe57
I haven't used XML Transformer stage, Just figured out it might be bale to achieve using that. Will try that out!!

Posted: Mon Oct 24, 2016 10:45 am
by chulett
XML is XML so that choice of stage shouldn't really matter.

Posted: Mon Oct 24, 2016 11:04 am
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>

Posted: Mon Oct 24, 2016 12:29 pm
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:

Posted: Mon Oct 24, 2016 12:47 pm
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.

Posted: Tue Oct 25, 2016 10:30 am
by tradersjoe57
Any thoughts?

Posted: Tue Oct 25, 2016 4:27 pm
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