Retrieving XML Custom Data

Highlighted
Six Stars

Retrieving XML Custom Data

Hi  All,

I am facing problem in retrieving certain fields like Location,Status,Source from below XML.  i tried with tFileInputXML, but its fetching all attributes id including unnecessary guest,Tax data. As  Can some Please Explain how can i Extract specified attributes(order-no,Location,Status,Source) from XML file.

 

Sample Source File:

 

<orders>
<order order-no="20001">
<manuals>
<manuals state-id="Location">Sydney</manuals>
<manuals state-id="Status">Success</manuals>
<manuals state-id="guest">false</manuals>
<manuals state-id="Tax">true</manuals>
<manuals state-id="Source">Web</manuals>
</manualss>
</order>
<order order-no="20002">
<manuals>
<manuals state-id="Location">Mexico</manuals>
<manuals state-id="Status">Success</manuals>
<manuals state-id="guest">false</manuals>
<manuals state-id="Source">Mobile</manuals>
</manualss>
</order>
</orders>

 

 

Thanks in Advance.


Accepted Solutions
Community Manager

Re: Retrieving XML Custom Attributes Data

Unfortunately your XML is not formatted correctly, but I am assuming that is just a copying error. Your custom-attributes elements are not closed properly (should be "</custom-attributes>").

 

To solve this you will need to loop in the tFileUnputXML like this.....

"/orders/order"

....and create one column called "order" with an xpath expression like this....

"."

Then add a tExtractXMLField component and extract your attributes here. Your loop should be ....

"/"

....and your column xpaths will need to look like this.....

"//custom-attribute[@attribute-id='Location']"

Obviously change the attribute-id value according to what you want to extract.

 

 


All Replies
Community Manager

Re: Retrieving XML Custom Attributes Data

Unfortunately your XML is not formatted correctly, but I am assuming that is just a copying error. Your custom-attributes elements are not closed properly (should be "</custom-attributes>").

 

To solve this you will need to loop in the tFileUnputXML like this.....

"/orders/order"

....and create one column called "order" with an xpath expression like this....

"."

Then add a tExtractXMLField component and extract your attributes here. Your loop should be ....

"/"

....and your column xpaths will need to look like this.....

"//custom-attribute[@attribute-id='Location']"

Obviously change the attribute-id value according to what you want to extract.

 

 

Six Stars

Re: Retrieving XML Custom Attributes Data


@rhall_2_0 wrote:

Unfortunately your XML is not formatted correctly, but I am assuming that is just a copying error. Your custom-attributes elements are not closed properly (should be "</custom-attributes>").

 

To solve this you will need to loop in the tFileUnputXML like this.....

"/orders/order"

....and create one column called "order" with an xpath expression like this....

"."

Then add a tExtractXMLField component and extract your attributes here. Your loop should be ....

"/"

....and your column xpaths will need to look like this.....

"//custom-attribute[@attribute-id='Location']"

Obviously change the attribute-id value according to what you want to extract.

 

 


Hey Thanks for quick reply. i have corrected end tag.

 

I tried in the same way as you explained, but its returning null value.

 

inputxml.JPGxmlfield.JPG

Community Manager

Re: Retrieving XML Custom Attributes Data

Can you run it the job and take a screen shot of the job just afterwards. Also, can you show me the whole xPath config for the tExtractXMLField component? 

Six Stars

Re: Retrieving XML Custom Attributes Data

Thanks alot rhall.

There is a spell mistake. its working as expected.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download