[xml] python xmlReader remains in previous attribute



This is effectively a reposting of
http://mail.gnome.org/archives/xml/2004-July/msg00035.html
since that message did not attract any replies.

With libxml2-2.6.11, the XmlReader does not appear to
move off an attribute and on to the next element after
Read() is done. Here is a test case to demonstrate the
problem:

#!/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 "node name: " + walk.Name()
 if walk.NodeType() ==
libxml2.XML_READER_TYPE_ELEMENT:
  while walk.MoveToNextAttribute():
   print 'attribute: %s="%s"' % (walk.Name(), \
    walk.Value())


This prints the following:
node name: doc
node name: #text
node name: element1
attribute: a1="1"
attribute: a2="2"
attribute: a3="3"
node name: a3
node name: a3
node name: a3
node name: a3
node name: a3

The right number of node names are printed but after
reading the attributes all node names have the value
of the last read attribute.

=====
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]