我正在使用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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。