[Tutor] XML Programs

Peter Otten __peter__ at web.de
Sat Apr 21 03:04:15 EDT 2018


Glen wrote:

> Thank you for your comprehensive reply. It was very helpful!
> Just to clarify one point, is it not possible to search for a node
> directly in the element / elementTree or do you first need to pull the
> data into a class/dict?

You certainly have other options

>>> catalog.xpath("//catalog/book[contains(title,'Guide')]/title/text()")
["XML Developer's Guide", 'MSXML3: A Comprehensive Guide', 'Visual Studio 7: 
A Comprehensive Guide']
>>> catalog.xpath("//catalog/book[starts-
with(author,'Corets')]/title/text()")
['Maeve Ascendant', "Oberon's Legacy", 'The Sundered Grail']

but then the question is whether you want to learn Python or XPath.



More information about the Tutor mailing list