python - 属性错误 : xmlNode instance has no attribute 'isCountNode'

标签 python xml centos libxml2 centos5

我正在编写的 Python 应用程序中使用 libxml2,并尝试运行一些测试代码来解析 XML 文件。该程序从 Internet 下载 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();

...基于 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() ,它仍然抛出了一个错误。

最佳答案

isCountNode 应为“lsCountNode”(小写“L”)

关于python - 属性错误 : xmlNode instance has no attribute 'isCountNode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/785972/

相关文章:

java - 使用本地更改覆盖 Maven 依赖项时发生冲突

xml - 在 xsd 中定义 xml,其中属性确定可能的内容

linux - Centos 7.0 更新命令不起作用

linux - 如何修复未在 CENTOS 上构建的 802.11 Linux STA broadcom 驱动程序?

python - 在numpy中淡出信号

python - 在 Django Admin 中使字段唯一

Python ElementTree 从根目录中删除元素时出错

xml - ISBN 13 的正则表达式

php - aws + centos 7 + 内置 nginx ngx_pagespeed + php-fpm = 找不到文件

python - 在 Amazon EC2 上安装适用于 Python 的 Google Cloud 客户端库时遇到错误