使用Python的ElementTree查找顶级xml注释

我正在使用Python的ElementTree解析xml文件,如下所示:

et = ElementTree(file=file("test.xml"))

test.xml以几行xml注释开头.

有没有办法从et得到这些评论

解决方法:

对于ElementTree 1.2.X,有一篇关于Reading processing instructions and comments with ElementTree

(http://effbot.org/zone/element-pi.htm)的文章.

编辑:

另一种选择是使用实现ElementTree API的lxml.etree.引用ElementTree compatibility of lxml.etree

ElementTree ignores comments and
processing instructions when parsing
XML, while etree will read them in and
treat them as Comment or
ProcessingInstruction elements
respectively.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念