GurdeepS
GurdeepS

Reputation: 67223

How to get this value via xpath

I have an xml document like so:

<add-server-response>
  <server id="4029" name="" notes="" state="Restoring Harddrive Image">
    <login name="iDRAC" username="dracadmin" password="Ah73849SJu57S1l"/>
    <ip name="system" address="199.16.205.97"/>
  </server>
</add-server-response>

From this, I want to get the value of id (4029), via Xpath. What would the corresponding xpath be and is there not a tool that would let me hover over an attribute and see the xpath query?

Thanks

Upvotes: 1

Views: 319

Answers (2)

Emiliano Poggi
Emiliano Poggi

Reputation: 24826

is there not a tool that would let me hover over an attribute and see the xpath query?

You may want have a look at:

These browser extensions, among many other useful functionalities, provide a "get XPath" like command on the selected node.

The XPath is returned as an exact (position dependent) and absolute location path.

Used directly on this web page I'm receiving:

/html/body/div[4]/div[2]/div[2]/div/table/tbody/tr/td[2]/div/div/pre/code/span[5]

But if you use it against an pure XML like your, you would receive:

/add-server-response/server/@id

Upvotes: 1

David Gladfelter
David Gladfelter

Reputation: 4213

/add-server-response/server/@id

Don't know of any tool

Upvotes: 1

Related Questions