Waqar Janjua
Waqar Janjua

Reputation: 6123

Write xpath for the node containing node value and attribute togetther

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.

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

Answers (1)

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

Related Questions