How to xpath on xml from query?

Four Stars KV
Four Stars

How to xpath on xml from query?

My scenario is this:

I have an sql query that extract a field that contains an xml.

I need to extract a specific value from this xml.

now the question is, how do I do this in talend?

I have tried using tJava, however the parse expects a URI and not a parameter from talend...

Nine Stars

Re: How to xpath on xml from query?

You have tXmlMap, tExtractXmlField to parse XML in Talend.

But, if you are using Sql Server (you mentioned - "I have an sql query") you will be able to perform xml parsing in database itself.

 

If you show your xml content and what exactly you are trying to achieve will help.

Four Stars KV
Four Stars

Re: How to xpath on xml from query?

image.png

this is my current job.

in tmap I have 20 fields. one of those fields contains an xml file.

I need to execute an xpath query on it to extract a specific tag.

question is, how do I execute xpath on a field coming from tmap? I tried using java code, but so far have been unsuccessful

Nine Stars

Re: How to xpath on xml from query?

@KV - are you sure one of such field in your tMap is a XML file and not some XML data.
If it's XML data then I would recommend you to pass it through tXMLMap like this - 

tXMLMap-1.JPGOnce the data is extracted then you could join it to tMap and perform your rest operation.

Nine Stars

Re: How to xpath on xml from query?

One more way would be to use tExtractXmlField. Sample job layout defined - 

tExtractXmlField-1.JPGSo, here mention the XML field and use XPath query to extract a specific tag and when done pass on the entire information to your tMap or other relevant components.