problems with xml parsing (python 3.3)
jannidis at gmail.com
jannidis at gmail.com
Mon Oct 29 18:54:43 EDT 2012
Am Sonntag, 28. Oktober 2012 03:27:14 UTC+1 schrieb jann... at gmail.com:
> Hello all,
>
>
>
> I am new to Python and have a problem with the behaviour of the xml parser. Assume we have this xml document:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <bibliography>
>
> <entry>
>
> Title of the first book.
>
> </entry>
>
> <entry>
>
> <coauthored/>
>
> Title of the second book.
>
> </entry>
>
> </bibliography>
>
>
>
>
>
> If I now check for the text of all 'entry' nodes, the text for the node with the empty element isn't shown
>
>
>
>
>
>
>
> import xml.etree.ElementTree as ET
>
> tree = ET.ElementTree(file='test.xml')
>
> root = tree.getroot()
>
> resultSet = root.findall(".//entry")
>
> for r in resultSet:
>
> print (r.text)
thanks a lot for your answer. as I am looking for a tool to teach using xml in programming it is a pity that this modul implements a very idiosyncratic view on xml data, but dom and sax are out there too, so I will look at them.
More information about the Python-list
mailing list