I was learning about repo, and noted that repo can use a “list of projects” to narrow down the scope of its actions. It will operate on the list of projects you give it, and not the others. But, as a newish member of the team, I didn’t know what the list of projects was. I knew there was a manifest file. It is in xml format.

I was never very successful with xml. However, I thought that time has passed, and maybe there is a newer easier to use tool out there. I looked again and found xmlstarlet. Maybe my previous attempts at xml have softened me up so I can understand xmlstarlet, or maybe it really is easier than previous xml tools.

I wanted an xmlgrep:

xmlstarlet sel -t -m "//project" -v "@path" -n default.xml

The “sel” subcommand “sel”ects nodes for processing.
The -t option says the following is a “template”. I don’t really understand this part, but it has to be there before the rest.
The -m option says “find the ‘project’ nodes”. This is an XPath expression. I don’t really know XPath that well but simple expressions can be as simple as //outer/inner for nodes called inner that are inside nodes called outer. That’s good enough for simple grep-like operations.
The -v option with the @ prefix on the arg means “get the value of the attribute ‘path’”.
The -n option means “put a newline here”. I guess it’s an element of the “template”. I guess the “template” is an output template, even though you are putting the criteria into the space between -t and the input file.
And then you give the input filename, default.xml.

Another handy command:

xmlstarlet el default.xml

Shows the structure of the document. This is the actual structure as opposed to the dtd structure.

xmlstarlet can do other stuff too — escape strings for xml (protect <, etc), and count stuff. Probably even add stuff up, and find the xxx nodes in yyy nodes that don’t have value zzz. But I haven’t tried those yet.

xmlstarlet gets bonus points for being apt-get able from a Debian stable system.