7 Oct
2009
7 Oct
'09
11:09 a.m.
Clif Swiggett wrote:
If I run the code:
test = etree.XML('<root><a/>text</root>') for x in test.iter(): print("%s - %s"%(x.tag, x.text))
I get the output:
root - None a - None
I expected that root.text would have been 'text' rather than none. However, if I flip the text and <a/> tag, then it works. E.g.
test = etree.XML('<root>text<a/></root>') for x in test.iter(): print("%s - %s"%(x.tag, x.text))
Output:
root - text a - None
Anyone know why this is, or how to work around it?
Sure, read the docs: http://codespeak.net/lxml/tutorial.html#elements-contain-text Stefan