Forrest logo
back to the xmllint tool

xmllint:tldr:8ffbc

xmllint: Return the href attribute of the second anchor element in an HTML file.
$ xmllint --html --xpath "string(//a[2]/@href)" webpage.xhtml
try on your machine

The command xmllint is a command-line utility for parsing XML documents. In this case, we are using it to parse an XHTML document.

The --html option tells xmllint to treat the input document as an HTML file rather than a strict XML file. This is because XHTML is essentially an HTML document written in XML syntax.

The --xpath option allows you to execute XPath expressions on the parsed document. XPath is a language used to navigate and query XML/HTML documents.

In this specific command, the XPath expression "string(//a[2]/@href)" is being executed on the XHTML document webpage.xhtml.

The XPath expression selects the second a element in the document (//a[2]), then retrieves the value of its href attribute (/@href). The string() function is used to convert the result to a string.

So, the command will output the value of the href attribute of the second a element found in the XHTML document webpage.xhtml.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the xmllint tool