Reputation: 8497
how do I print the title value for the below html
file using xmlstarlet
?
thufir@doge:~/.html$
thufir@doge:~/.html$ xmlstarlet sel -t -v "/html/header[@name='title']" -n hello.html
thufir@doge:~/.html$
thufir@doge:~/.html$ cat hello.html
<html>
<header><title>This is title</title></header>
<body>
Hello world
</body>
</html>
thufir@doge:~/.html$
Grabbing xml
might be a bit different than html? Assuming garden-variety html
and not xhtml
.
The reason I'm using xmlstarlet
is specifically to use xpath
syntax which seems rather alien.
Upvotes: 0
Views: 2206
Reputation: 3919
With:
"/html/header[@name='title']"
you select an header
element which has an attribute name
with the value "title".
What you want is to grab a title
element in an header
element:
//header/title
or just use :
//title
which selects all title elements, regardless of its position in the tree.
Upvotes: 2
Reputation: 15435
I'd just cheat and use Chrome's Developer Tools.
Open the HTML in Chrome, open the Developer Tools, then in the Elements tab, right click and select Copy > Copy XPath.
/html/body/header/title
Upvotes: 1