Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath: is it possible to combine queries

Tags:

xml

xpath

Consider the following XML:

<root>
  <steps>
    <step>1</step>
    <step>2</step>
    <step>3</step>
    <step>4</step>
  </steps>
  <stepDetails step="1">Details</stepDetails>
  <stepDetails step="2">Details</stepDetails>
  <stepDetails step="3">Details</stepDetails>
</root>

What I need to do is find all the steps that do not have corresponding stepDetails. In the above example, only the "<step>4</step>" node would be returned.

Now, I know I can do that by querying all the steps, iterating through the collection and performing another query for each iteration. I'm hoping that there is a way of doing that with just one query. Perhaps using something like SQL's IN statement and a sub-query.

Any ideas or tips would be most appreciated.

thnx, Christoph

like image 943
Christoph Avatar asked Sep 16 '11 14:09

Christoph


People also ask

Can we combine 2 Xpaths?

Use following or preceding Advanced Xpath to combine the two xpath.

Is XPath a query language?

XPath (XML Path Language) is a query language that can be used to query data from XML documents. In RUEI, XPath queries can be used for content scanning of XML documents. A complete specification of XPath is available at http://www.w3.org/TR/xpath .

What does and mean in XPath?

W.R.T to your first questions, if we don't use '. ' (dot) at the beginning, then you will be basically selecting all element nodes with an @id-attribute-value equal to 'Passwd' from the entire document. By adding '//*' in XPath you would be selecting all the element nodes from the entire document.


1 Answers

Try this:

/root/steps/step[not(. = /root/stepDetails/@step)]
like image 142
Mike Sokolov Avatar answered Oct 05 '22 11:10

Mike Sokolov