views:

484

answers:

1

I'm using libxml2 in a Python app I'm writing, and am trying to run some test code to parse an XML file. The program downloads an XML file from the internet and parses it. However, I have run into a problem.

With the following code:

xmldoc = libxml2.parseDoc(gfile_content)

droot = xmldoc.children         # Get document root
dchild = droot.children         # Get child nodes

while dchild is not None:
        if dchild.type == "element":
                print "\tAn element with ", dchild.isCountNode(), "child(ren)"
                print "\tAnd content", repr(dchild.content)
        dchild = dchild.next
xmldoc.freeDoc();

...which is based on the code example found on this article on XML.com, I receive the following error when I attempt to run this code on Python 2.4.3 (CentOS 5.2 package).

Traceback (most recent call last):
  File "./xml.py", line 25, in ?
    print "\tAn element with ", dchild.isCountNode(), "child(ren)"
AttributeError: xmlNode instance has no attribute 'isCountNode'

I'm rather stuck here.

Edit: I should note here I also tried IsCountNode() and it still threw an error.

+3  A: 

isCountNode should read "lsCountNode" (a lower-case "L")

Ryan Brunner
Hmm, I've tried that and it still throws an error.
Jonathan Prior
Is it the same error? (i.e. xmlNode instance has no attribute "lsCountNode"?)
Ryan Brunner
Yes, it is. (15char)
Jonathan Prior
Oh, hold on, I misread your answer. Sorry!
Jonathan Prior