[xml] python xmlReader attribute confusion



XmlReader appears to get stuck within attributes...
I'm not sure whether it is expected behaviour...
Here's my test code on libxml2-2.6.6-1mdk:

#!/usr/bin/env python
import libxml2

xml = """<doc>
<element1 a1="1" a2="2" a3="3"></element1>
<element2>test</element2></doc>"""

doc = libxml2.parseDoc(xml)
walk = doc.readerWalker()

while (walk.Read()):
 print walk.Name()
 if walk.NodeType() ==
libxml2.XML_READER_TYPE_ELEMENT:
  while walk.MoveToNextAttribute():
   print ' %s="%s"' % (walk.Name(), walk.Value())

It seems to end up printing a3 for every node after
reading the a3 attribute unless I add
walk.MoveToElement() after the while loop. It would be
handy if it didn't need to be manually reset like that
though (or if a note was added to the docs).

=====
Sitsofe | http://sucs.org/~sits/


        
        
                
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new 
ways to express yourself http://uk.messenger.yahoo.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]