1

Lets say I have this xml:

<Root>
    <Node size="Foo" />
<Root>

In order to get the values of attributes I run this command:

echo "<Root><Node size='foo' /></Root>"  | xmllint -xpath "/Root/Node/@size" -

(note the - at the end)

And this will return foo.

Now my question is how can I have xmllint return me the name of the element which is Node?

I have tried doing:

echo "<Root><Node size='foo' /></Root>"  | xmllint -xpath "/Root/Node/name()" -

but that does not seem to work.

Tono Nam
  • 34,064
  • 78
  • 298
  • 470

1 Answers1

3

The XPath you're using requires XPath 2.0, while xmllint supports only XPath 1.0.

Change your XPath to this XPath 1.0 expression,

name(/Root/Node)

and you'll echo the name of the selected node, Node, as requested.

kjhughes
  • 106,133
  • 27
  • 181
  • 240