Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

XPath not working properly in tExtractXMLField / tXMLMap

This is my sample XML

<shiporder>
 <items>
  <item>
    <title>Empire Burlesque</title>
    <note>Special Edition</note>
    <quantity>1</quantity>
    <price>10.90</price>
  </item>
  <item>
    <title>Hide your heart</title>
    <quantity>1</quantity>
    <price>9.90</price>
  </item>
 </items>
</shiporder>



My XPath query doesn't give the expected output , i.e. it should give both the titles whereas its giving the first title only.
I tried below XPath:
- //shiporder/items/item[position()<3]/title
- //title

Shouldn't Talend give proper output for my above XPath strings ?0683p000009MFH9.png

Labels (2)
4 Replies
Anonymous
Not applicable
Author

If you want data for every title, you need to set the loop xpath. You have set it to "/".
Anonymous
Not applicable
Author

rhall_2.0 wrote:
If you want data for every title, you need to set the loop xpath. You have set it to "/".

Yes, the Loop XPath query was already set to "/" . Attached is screenshot of my job
Still it doesn't work as expected.
0683p000009MFIR.png
Anonymous
Not applicable
Author

No, what I meant was that "/" is wrong. You need to set it to an XPath that points to the looping element. Otherwise only the first value in a series of loops will be returned. This is the correct behaviour.
Anonymous
Not applicable
Author

Thanks rhall_2.0
I found that when i use these:
[size=1][font=Verdana, Helvetica, Arial, sans-serif]- //shiporder/items/item[position()<3]/title[/font][/size]
- //title
in Loop XPath query, and put "." in XPath query, it works as i wanted. But this is putting the Xpath query in the loop section.

If I simply point to the looping element in Loop Xpath query i.e. set it to //shiporder/items/item (also tried //shiporder/items) and put the //title (or //item/title) in the XPath query, it doesn't work. Is this the expected behaviour ?



And to come to what i'm intending to do...
I want to use tExtractXMLField or tXMLMap to convert the input XML as in my first post, to a CSV of the 2 /shiporder/items/item/title fields. So the output CSV should look like:
Empire Burlesque, Hide your heart


I found a way to do this using tExtractXMLField with a bit of Java routine, but i think it should be doable by using these 2 components and XPath. Do you think it can be done that way ?