Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I reproduced an issue I'm getting when attempting to retrieve data from an XML file using an xpath text() query whenever there is & in the string to be returned.
Here are the contents of a simple XML file I created:
<root><field id="name">A &amp; B</field></root>
On an xpath testing site such as freeformatter.com, the xpath query of "/root/field[@id='name']/text()" returns the text: 'A &amp; B' as expected.
However, in Talend, when I use a tFileInputXML component, using /root as the loop element and the same xpath query in the mapping section, the data returned is simply 'A'
Is this a bug in the tFileInputXML component? Or is there a way to update my xpath query so it returns the complete string?
Hello @bon shih ,
If you setup the xpath query to "./field[@id='name']" in tFileInputXML component as the below, it will work as expected.
Best regards
Aiming
This is great, and appears to be working. Can you explain the difference between fetching the data with or without the text() function? When I initially looked for Xpath examples to return the text contained in a field, they all used the text() function. It's also puzzling that the Xpath validator accepted it without a problem. Will there be any cases where omitting this will cause an issue?
without the text() function, it will return the whole text of the xpath element. with the text() function, it may return one text of the element as it contains special character &
if the text doesn't contains &, e.g. <root><field id="name">A amp;amp; B</field></root>, then the xpath
"/root/field[@id='name']/text()" and "/root/field[@id='name']" will return the same results
>with the text() function, it may return one text of the element
Is this behavior a result of a bug in the Talend component? My understanding is that text() should also return the entire string (regardless of special characters), just as it does on an xpath validator site such as freeformatter.com