2009-04-24 80 views
0

我在寫一個Python應用程序中使用libxml2,並試圖運行一些測試代碼來解析XML文件。該程序從互聯網上下載一個XML文件並對其進行分析。但是,我遇到了一個問題。AttributeError:xmlNode實例沒有屬性'isCountNode'

用下面的代碼:

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(); 

...這是基於this article on XML.com找到的代碼示例中,我收到以下錯誤,當我嘗試在Python的2.4.3版本(CentOS 5.2運行這段代碼包)。

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' 

我寧願呆在這裏。

編輯:我應該注意到在這裏我也試過IsCountNode(),它仍然拋出一個錯誤。

回答

3

isCountNode應改爲「lsCountNode」(小寫的「L」)

+0

嗯,我已經試過了,它仍然拋出一個錯誤。 – 2009-04-24 14:05:11

相關問題