problems with xml parsing (python 3.3)

MRAB python at mrabarnett.plus.com
Sat Oct 27 23:08:55 EDT 2012


On 2012-10-28 02:27, jannidis at gmail.com wrote:
> 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)
>
It _is_ shown, it's just that it's all whitespace:

 >>> for r in resultSet:
	print(ascii(r.text))

	
'\n            Title of the first book.\n        '
'\n            '




More information about the Python-list mailing list