O'Reilly logo

XML Processing with Python by Sean McGrath

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required