Suppose this is my XML:
<myxml>
<data key="true">Apple</data>
<data key="true">banana</data>
<data1 key="true">banana</data1>
<data>Apple</data>
</myxml>
I need an XPath expression for the tag which contains attribute key="true" and node value = Apple.
I tried different combinations but not succeeded.
- For attribute I use this
xpath="/myxml/data[@key='true'] - and for Node value I use this
xpath = "/myxml/data[. ='Apple']/ - and also try this
xpath = "/myxml/data[.='Apple'][@key='true]/
but got error.
I have multiple tags in the xpath. /mappings/mapping[data[@iskey='true'][.='apple'] and data1[@iskey='true'][.='banana']/
There is a mistake in this path.
How I specify both the attribute and node value together ?
You need to use the ‘and’ operator.
From your example:
Look under http://www.w3schools.com/xpath/xpath_operators.asp for more information on xpath operators.