A while ago, I heard about xmllint, a program that can parse and query xml from the command-line.
Later, I discovered it can also parse html, can recover from xml/html errors and has an interactive shell that has a lot of commands (see table below) to navigate through the loaded command.
The relevant command-line options:
Some good examples of usage are here:
- Hack 35 Explore a Document Tree with the xmllint Shell :: Chapter 3. Transforming XML Documents :: xml hacks :: XML :: eTutorials.org.
- Your XML friend XPATH command line xmllint » Linux by Examples. (it uses the grep command which is not in the official command table below)
- The xmllint Shell. (mentions the grep command, but no example of it)
- openSUSE Lizards: Playing With XPath Expressions in The xmllint Shell.
- Re: [xml] xmllint – Browsing in file with default namespace.
- xpath – Possible to process XHTML with Saxon? – Stack Overflow.
The table of shell commands:
xmllint offers an interactive shell mode invoked with the –shell command. Available commands in shell mode include: Command Parameter Description base display XML base of the node bye leave shell cat node Display node if given or current node. cd path Change the current node to path (if given and unique) or root if no argument given. dir path Dumps information about the node (namespace, attributes, content). du path Show the structure of the subtree under path or the current node. exit Leave the shell. help Show this help. free Display memory usage. load name Load a new document with the given name. ls path List contents of path (if given) or the current directory. pwd Display the path to the current node. quit Leave the shell. save name Saves the current document to name if given or to the original name. validate Check the document for error. write name Write the current node to the given filename.