1

I have several nodes (see below). I know how to select specific nodes which have a certain attribute. But in this case I would like to import the "file_url" value of the media objects that belong to the group "narrowImage".

<media_object>

 <media_object>
  <file_id>5175967</file_id>
  <group>wideImage</group>
  <file_url>http://www.mysite.com/image1.jpg</file_url>
 </media_object>

 <media_object>
  <file_id>5175968</file_id>
  <group>wideImage</group>
  <file_url>http://www.mysite.com/image2.jpg</file_url>
 </media_object>

 <media_object>
  <file_id>5175969</file_id>
  <group>narrowImage</group>
  <file_url>http://www.mysite.com/image3.jpg</file_url>
 </media_object>

</media_object>

In the above case i would only need the value "http://www.mysite.com/image3.jpg"

any xpath expert out there who can point me in the right direction?

2 Answers 2

2

Use:

/*/*[group = 'narrowImage']/file_url

This selects any file_url element that is a "grand-child" of the top element in the XML document, and whose parent has a group child-element whose string value is 'narrowImage'.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you dimitre, i didnt quite know which keywords to use in my search, helped me out a bunch
@WilliamLekatompessy: You are welcome. You can use The XPath Visualizer tool for learning XPath the fun way: huttar.net/dimitre/XPV/TopXML-XPV.html
0

I think you should be able to use:

//media_object[group='narrowImage']/file_url

This should select every media_object in your file (regardless of the level) then filter them based on group='narrowImage' then give you the file_url child.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.