Reputation: 6123
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.
xpath="/myxml/data[@key='true']
xpath = "/myxml/data[. ='Apple']/
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 ?
Upvotes: 0
Views: 537
Reputation: 929
You need to use the 'and' operator.
From your example:
/myxml/data[.='Apple' and @key='true']
Look under http://www.w3schools.com/xpath/xpath_operators.asp for more information on xpath operators.
Upvotes: 3