<?xml>
<env>
<body>
<folderxml>
<folder id='1'>
<folder id='2' name ='document'>
<folder id='3' name ='Music'>
<folder id= '4' name= 'album' xlink='true'>
</folder>
</folder>
</folder>
</folder>
</folderxml>
</body>
</env>
I need the path if the attribute ‘link’ is true. Something like xpath.evaluate(path if(link=true)). The result should be something like “/documents/music/album”
After applying the following XPath expression (based on XPath tutorial):
you obtain a link to the node list. In the example it is a single node
folderwithid4. Then you need to write a function that will travell all the parents and concatenate theirnameattributes.If you needed only the name of the matching folder, than you could go with
and read the
stringvalmember of the result. But that matches only the first node.Edit: As for the function to iterate over parents I thought of direct access through
xmlNodePtr->parentmember and reading attributes withxmlGetProp. But as I see your comment (and also the title of the question) I think that you could make use of relative xpath queries, see What’s the most efficient way to do recursive XPath queries using libxml2?.