属性错误:xmlNode 实例没有属性“isCountNode”
题
我正在编写的 Python 应用程序中使用 libxml2,并尝试运行一些测试代码来解析 XML 文件。该程序从互联网下载 XML 文件并对其进行解析。但是,我遇到了一个问题。
使用以下代码:
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();
...这是基于在上找到的代码示例 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() 但它仍然抛出错误。
解决方案
isCountNode应改为 “lsCountNode”(小写 “L”)
不隶属于 StackOverflow