I have a following xml:
<doc> <divider /> <p>text</p> <p>text</p> <p>text</p> <p>text</p> <p>text</p> <divider /> <p>text</p> <p>text</p> <divider /> <p>text</p> <divider /> </doc>
I want to select all p nodes after first divider element until next occurrence of divider element. I tried with following xpath:
//divider[1]/following-sibling::p[following::divider]
but the problem is it selects all p elements before last divider element. I'm not sure how to do it using xpath 1.
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 .
XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system. XPath expressions can be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.
Syntax of XPath Below is the syntax for Xpath: Xpath =//tagname[@Attribute='value'] Wherein: //: Used to select the current node. tagname: Name of the tag of a particular node.
Same concept as bytebuster, but a different xpath:
/*/p[count(preceding-sibling::divider)=1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With