【发布时间】:2016-09-08 12:16:08
【问题描述】:
我有一个使用 python 的lxml.objectify 库读取的 XML 文件。
我没有找到获取 XML 注释内容的方法:
<data>
<!--Contents 1-->
<some_empty_tag/>
<!--Contents 2-->
</data>
我能够检索评论(有没有更好的方法?xml.comment[1] 似乎不起作用):
xml = objectify.parse(the_xml_file).getroot()
for c in xml.iterchildren(tag=etree.Comment):
print c.???? # how do i print the contets of the comment?
# print c.text # does not work
# print str(c) # also does not work
正确的方法是什么?
【问题讨论】:
-
我不希望能够用 xml 库解析 cmets;根据定义,它们不是 xml 结构的一部分,并且总是可以被任何工具忽略
标签: python lxml.objectify