XPath with multiple conditions

What XPath can I use to select any category with a name attribute specified and any child node author with the value specified. I’ve tried different variations of the path below with no success: //quotes/category[@name=”Sport” and author=”James Small”] The XML: <?xml version=”1.0″ encoding=”utf-8″?> <quotes> <category name=”Sport”> <author>James Small<quote date=”09/02/1985″>Quote One</quote><quote date=”11/02/1925″>Quote nine</quote></author> </category> <category name=”Music”> … Read more

How to execute XPath one-liners from shell?

Is there a package out there, for Ubuntu and/or CentOS, that has a command-line tool that can execute an XPath one-liner like foo //element@attribute filename.xml or foo //element@attribute < filename.xml and return the results line by line? I’m looking for something that would allow me to just apt-get install foo or yum install foo and … Read more

XPath to select Element by attribute value

I have following XML. <?xml version=”1.0″ encoding=”UTF-8″?> <Employees> <Employee id=”3″> <age>40</age> <name>Tom</name> <gender>Male</gender> <role>Manager</role> </Employee> <Employee id=”4″> <age>25</age> <name>Meghna</name> <gender>Female</gender> <role>Manager</role> </Employee> </Employees> I want to select Employee element with id=”4″. I am using below XPath expression which is not returning anything. //Employee/[@id=’4′]/text() I checked it at http://chris.photobooks.com/xml/default.htm and it says invalid xpath, not sure … Read more

How to verify an XPath expression in Chrome Developers tool or Firefox’s Firebug?

How can I verify my XPath? I am using Chrome Developers tool to inspect the elements and form my XPath. I verify it using the Chrome plugin XPath Checker, however it does not always give me the result. What is a better way to verify my XPath. I have also tried using Firebug to inspect … Read more

XPath: Get parent node from child node

I need get the parent node for child node title 50 At the moment I am using only //*[title=”50″] How could I get its parent? Result should be the store node. <?xml version=”1.0″ encoding=”utf-8″?> <d:data xmlns:d=”defiant-namespace” d:mi=”23″> <store d:mi=”22″> <book price=”12.99″ d:price=”Number” d:mi=”4″> <title d:constr=”String” d:mi=”1″>Sword of Honour</title> <category d:constr=”String” d:mi=”2″>fiction</category> <author d:constr=”String” d:mi=”3″>Evelyn Waugh</author> … Read more

XPath: How to select elements based on their value?

I am new to using XPath and this may be a basic question. Kindly bear with me and help me in resolving the issue. I have an XML file like this: <RootNode> <FirstChild> <Element attribute1=”abc” attribute2=”xyz”>Data</Element> <FirstChild> </RootNode> I can validate the presence of an <Element> tag with: //Element[@attribute1=”abc” and @attribute2=”xyz”] Now I also want … Read more

XPath to select element based on childs child value

Trying to select an element based on the value of one of it’s childrens childrens Thinking the following but not working, appreciate any help, thanks ./book[/author/name=”John”] or ./book[/author/name text() = ‘John’] Want all books where the author name=”John” Xml file <list> <book> <author> <name>John</name> <number>4324234</number> </author> <title>New Book</title> <isbn>dsdaassda</isbn> </book> <book>…</book> <book>…</book> </list> 1 Answer … Read more