XPath with multiple conditions
Try: //category[@name=”Sport” and ./author/text()=’James Small’]
Try: //category[@name=”Sport” and ./author/text()=’James Small’]
//a[contains(@prop,’Foo’)] Works if I use this XML to get results back. <bla> <a prop=”Foo1″>a</a> <a prop=”Foo2″>b</a> <a prop=”3Foo”>c</a> <a prop=”Bar”>a</a> </bla> Edit: Another thing to note is that while the XPath above will return the correct answer for that particular xml, if you want to guarantee you only get the “a” elements in element “bla”, … Read more
<xsl:if test=”xpath-expression”>…</xsl:if> so for example <xsl:if test=”/html/body”>body node exists</xsl:if> <xsl:if test=”not(/html/body)”>body node missing</xsl:if>
You should try these tools : xmlstarlet (xmlstarlet page) : can edit, select, transform… Not installed by default, xpath1 xmllint (man xmllint): often installed by default with libxml2-utils, xpath1 (check my wrapper to have –xpath switch on very old releases and newlines delimited output (v < 2.9.9)). Can be used as interactive shell with the … Read more
You need to remove the / before the [. Predicates (the parts in [..]) shouldn’t have slashes immediately before them – they go directly after the node selector they are associated with. Also, to select the Employee element itself, you should leave off the /text() at the end. Otherwise you’d just be selecting the whitespace … Read more
Chrome This can be achieved by three different approaches (see my blog article here for more details): Search in Elements panel like below Execute $x() and $$() in Console panel, as shown in Lawrence’s answer Third party extensions (not really necessary in most of the cases, could be an overkill) Here is how you search … Read more
The condition below: //Element[@attribute1=”abc” and @attribute2=”xyz” and Data] checks for the existence of the element Data within Element and not for element value Data. Instead you can use //Element[@attribute1=”abc” and @attribute2=”xyz” and text()=”Data”]
Use the parent axes with the parent node’s name. //*[title=”50″]/parent::store This XPath will only select the parent node if it is a store. But you can also use one of these //*[title=”50″]/parent::* //*[title=”50″]/.. These xpaths will select any parent node. So if the document changes you will always select a node, even if it is … Read more
Yup, it’s called JSONPath: It’s also integrated into DOJO.
Almost there. In your predicate, you want a relative path, so change ./book[/author/name=”John”] to either ./book[author/name=”John”] or ./book[./author/name=”John”] and you will match your element. Your current predicate goes back to the root of the document to look for an author.