8.4. Adding XML Search Features to xgrep
The current code is a good start on the road to an XML-aware grep, but there are a number of improvements we can make quite easily. Now seems as good a time as any to add them. We will allow xgrep to do the following.
Use a validating source of XML events (i.e., xmlv)
Match on attribute names
Match on attribute values
Match on processing instructions
Match on element type names
Adding these to the code is a lot easier than dreaming up a sensible way to specify them with single-letter command options! Thankfully, Python's getopt library supports the use of multicharacter command options that are preceded with two rather than one hyphen. Here are the new options we will add.
--V Turn on validation
--AN Match ...