Search this site





xpathtool - powerful xpath queries on the commandline

What is xpathtool?

Short version: xpath query tool for xml and html.

Long version: swanky frontend to xsltproc which takes an xpath query and content and spits out the results.

Dependencies: xsltproc (comes with libxslt), xmllint (comes with libxml2).




Set input format as html.
Output should be text. Implemented as <xsl:value-of select="." />
Output should be xml.
Output should be html.
--indent (default) or --noindent
Set whether or not xml or html output should be depth-based indented.
Define elements who's content should be space-stripped. Implemented with <xsl:strips-ace>.
--pretty (default) or --nopretty
Pretty print xml and html output by filtering through 'xmllint --format'

Example: Technorati WTF RSS

% GET | ./ '//link' | tail -3

Example: Slashdot article links

Slashdot is worthless. The article writeups are worthless. The comments are worthless. The users are worthless.

Sometimes, the linked content is not. Let's pull out all the links in all the articles on the frontpage:
# slashdot articles are inside the following html element
% xbase="//div[@class='article']//div[@class='intro']/i"
% GET | ./ --ihtml "$xbase//a/@href|$xbase//a/text()"  | paste -d" " - - the world's biggest digital dump turn over their entire email operation to Google the dark side of Google's offer