Is their a way to use XPATH query for XML generated in stream?

One Star

Is their a way to use XPATH query for XML generated in stream?

Hello,
I am new to Talend. I have created a job to read an xml and extract data based on XPath queries. I am able to do this successfully by reading the XML file in tfileInputXML component and then writing XPath queries.
But is their any way to read the XML from stream and extract the xml elements based on XPATH query from XML file which is not located on local system but instead might be generated in stream.
tfileInputXML --- txmlMap --Other components
Moderator

Re: Is their a way to use XPATH query for XML generated in stream?

Hi,
But is their any way to read the XML from stream and extract the xml elements based on XPATH query from XML file which is not located on local system but instead might be generated in stream.

You can read a XML file generated from stream from "File Name/Stream" as your screenshot shown.
Please have a look at the on-line component reference tFileInputXML
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Is their a way to use XPATH query for XML generated in stream?

Thanks for quick reply. I did looked up in the documentation but could not figure out how to get my problem solved. I am giving some more details of my problem. Meanwhile I will also be trying from my side..
Here's how my talend job looks like:

tesbProviderRequest -------tExtractXMLField------tFileOutputXML ---onCompOk------tFileInputXML-- other components
I am reading the request XML and constructing new XML using tExtractXMLField component. The resultant XML I am writing in a file using tFileOutputXML. Then I am reading it using tFileInputXML and using XPATH queries to get what I want.
the problem is I don't want to write in a file as it might involve issues like server space or other issues..
Thanks,


Hi,
But is their any way to read the XML from stream and extract the xml elements based on XPATH query from XML file which is not located on local system but instead might be generated in stream.

You can read a XML file generated from stream from "File Name/Stream" as your screenshot shown.
Please have a look at the on-line component reference tFileInputXML
Best regards
Sabrina
Community Manager

Re: Is their a way to use XPATH query for XML generated in stream?

Hi
The tFileInputXML read the xml file generated by tFileOutputXML? If so, I don't understand why you generate the xml file if you don't want to do it. To me, extract the data from xml request with tExtractXMLField or tXMLMap, and then pass directly them to other component or store them into memory for use later.
Am I misunderstand your request?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Is their a way to use XPATH query for XML generated in stream?

Hi
The tFileInputXML read the xml file generated by tFileOutputXML? If so, I don't understand why you generate the xml file if you don't want to do it. To me, extract the data from xml request with tExtractXMLField or tXMLMap, and then pass directly them to other component or store them into memory for use later.
Am I misunderstand your request?
Shong

thanks for replying shong. I have learnt a lot from your posts all over the forum. I have reached this far but I am stuck here due to performance issue..
My problem is I need to extract data from XML file using XPATH query. The only component I came across doing so is tfileInputXML..
For this reason I write the XML in a file and then read it using tfileInputXML and extract data using XPATH.
Please suggest something (component or some flow ) that will read the XML from textractXMLfield and directly allow me to give XPATH to get the data without having me to store the XML in a file..
Thanks
Community Manager

Re: Is their a way to use XPATH query for XML generated in stream?

Hi
You just need a tXMLMap to extract data from a Document, tesbProviderRequest sends a Document, not a string. The job design looks like:
tesbProviderRequest --main--tXMLMap---main--other component.
I suggest you to learn tXMLMap component.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Is their a way to use XPATH query for XML generated in stream?

hello shong,

I agree tXMLMap will get XML in document form. But I need to extract nodes element values from this XML based on XPATH and then construct an XML using tXMLMap mapping each value..
For ex,
if XML from tesbProviderRequest is something like:
<Root>
<Student>
<Name>XYZ</Name>
<Subject>ABC</Subject>
</Student>
</Root>
I can extract Name and subject values if I give XPATHs like:
/Root/Student/Name/text()
/Root/Student/Name/subject/text()

But I was not able to find any way to do with tXMLMap. Thats why I ended up using tfileInputXml component..
My job looks something like
tesbProviderRequest --main--tExtractXMLField---main--tfileOutputXML--onComponentOK--tfileInputXML--tXMLMAP

tExtractXMLField constructs an XML from which I need to extract values..
-tfileOutputXML--onComponentOK--tfileInputXML seems unneccesary to me and seems a issue as for each request I can't afford to write in files..
tfileInputXml component has one option like File name/ stream.. Can you please suggest me anything how to use the "stream" option.
Community Manager

Re: Is their a way to use XPATH query for XML generated in stream?

Hi
As you said, you have used tExtractXMLField to extract values from a string with xml format, why don't you pass directly the values to other component? instead of writing them to a xml file and then read them back with a tFileinputXML component?
Can you show me the schema of the webservice request?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Is their a way to use XPATH query for XML generated in stream?

Hi,

How to get the value "homeDefault" and "true" from below xml
<name>
<chChSelectionMode><homeDefault/></chChSelectionMode>
<dynamicAddressFlag><true/></dynamicAddressFlag>
</name>

Since the tool identifies <homeDefault/> as tag but it is actually a value ,how to mention the xpath value in xml metadata