gayashanbc
gayashanbc

Reputation: 1014

xPath attribute equals operator not working as expected

I have the following xml document.

<?xml version="1.0" encoding="UTF-8"?>
<LevelOne>
    <LevelTwo>
        <LevelThree class="MyClass">
            <Property name="FirstName">hello</Property>
            <Property name="SecondName">bar</Property>
            <Property name="ThirdName">world</Property>
            <Property name="FourthName">foo</Property>
        </LevelThree>
    </LevelTwo>
</LevelOne>

When I run the following xPath query,

xpath my.xml //Property

Gives me the following results where all the nodes are selected. Result of the first query

Now, I want to select the node where the name attribute of the node is equal to FirstName. I came up with following xPath query after going through some examples on the internet.

xpath my.xml //Property[@name='FirstName']

And I end up getting the following result on both macOS and Ubuntu terminals. Result of the second query

What am I possibly doing wrong here?

Upvotes: 1

Views: 150

Answers (1)

gayashanbc
gayashanbc

Reputation: 1014

As pointed out in @Robby Cornelissen's answer, the issue seems to be with the quotations. Wrapping the query inside quotations as follows solved the problem.

xpath my.xml "//Property[@name='FirstName']"

Upvotes: 1

Related Questions