문제

나는 내가 쓰고있는 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")을 읽어야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top