Saikat
Saikat

Reputation: 16860

Checking if the same text is appearing under 2 different xpath

I have 2 xpaths as - //xpath1/text() and //xpath2/text() I want to form a single xpath conditional expression which will verify if the text is same for both.

Is that possible? I am ok to tweak the xpaths.

EDIT

..
    <test id="1">
        <testcase attr1="xyz">Jane</partyId>
        <testcase attr2="abc">Doe</partyId>
    </test>

    <test id="2">
        <testcase attr1="xyz">Jane</partyId>
        <testcase attr2="abc">Does</partyId>
    </test>
..

I want to verify if the text under //test[@id="1"]/testcase[@attr1="xyz"] and //test[@id="2"]/testcase[@attr1="xyz"] is same.

Upvotes: 0

Views: 29

Answers (1)

宏杰李
宏杰李

Reputation: 12168

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
    <actors>
        <actor id="1">Christian Bale</actor>
        <actor id="2">Liam Neeson</actor>
        <actor id="3">Michael Caine</actor>
    </actors>
    <foo:singers>
        <foo:singer id="4">Tom Waits</foo:singer>
        <foo:singer id="5">B.B. King</foo:singer>
        <foo:singer id="6">Ray Charles</foo:singer>
    </foo:singers>
</root>

XPATH:

//actors[string(.)=string(//foo:singers)]

OUT:

NO MATCH!

ATTATION:

The string() function converts a node-set to a string by returning the string value of the first node in the node-set, which in some instances may yield unexpected results.

If you want the string() function to concatenate all child text, you must then pass a single node instead of a node-set.

string Function

Upvotes: 1

Related Questions