[xml] reader.Next()



Hi Daniel, All,

I'm confused about what is xmlTextReaderNext actually supposed to do.
When I use it with a TextReader, it works almost like like 
xmlTextReaderNextSibling for walker, except that it stops before the end-tag. 
For Walker, Next() seems to work just like Read(), except that it starts with 
the current node, rather than skipping it.

I guess I have to look at the reader status, too, but still I'm confused. The 
description of Next() and NextSibling() in the docs is the same. The same 
code for TextReader and Walker does different things.

Any hints?

Here a sample code in python that does some comparison:

#!/usr/bin/env python
import libxml2
import sys
import StringIO

str = """<a><start/><aa><cc/></aa><bb><cc/></bb></a>"""
f = StringIO.StringIO(str)
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test_next")

print "Next on TextReader"
reader.Read()
reader.Read()
while reader.Next():
    print reader.Name()
print "---"

print "NextSibling on Walker"
doc = libxml2.parseDoc(str)
reader = doc.readerWalker()
reader.Read()
reader.Read()
while reader.NextSibling():
    print reader.Name()

print "---"
print "Next on Walker"
doc = libxml2.parseDoc(str)
reader = doc.readerWalker()
reader.Read()
reader.Read()
while reader.Next():
    print reader.Name()

print "---"
print "Read on Walker"
doc = libxml2.parseDoc(str)
reader = doc.readerWalker()
reader.Read()
reader.Read()
while reader.Read():
    print reader.Name()

##########################

Thanks,
-- Petr



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