On Wed, 2009-10-07 at 10:45 -0700, 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? Thanks! - Clif
_______________________________________________ lxml-dev mailing list lxml-dev@codespeak.net http://codespeak.net/mailman/listinfo/lxml-dev
Take a look at the tutorial, especially the "Elements contain text" section near here: http://codespeak.net/lxml/tutorial.html#the-element-class Hopefully that will explain how .text and .tail work for accessing text. The short answer is that your text is in test.find( 'a' ).tail, though. The itertext method may also be useful for you, depending on your use case. -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company