Chapter 9. Tree-driven XML Processing

In chapter 8, we made xgrep XML-aware by allowing it to feed off the PYX notation produced by xmln and xmlv.

In this chapter, we extend xgrep again by allowing it to answer queries like these.

  • Find “Sean” anywhere within a name element.

  • Print the text content of price elements.

  • Count the number of invoice elements that have an overdue child element.

All the above queries share a common characteristic: They are most easily answered by modelling XML as a hierarchical structure. Answering queries like these with xgrep as it currently stands is not possible.

We can find “Sean” in data content easily, but we cannot restrict matches to “Sean” occurring somewhere within a name element.

What we need to answer these ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.