访问位于根元素之前的 XML 注释
请帮我解决 lxml 的问题。 如何从此文件中获取“注释 1”?
<?xml version="1.0" encoding="windows-1251" standalone="yes" ?>
<!--Comment 1-->
<a>
<!--Comment 2-->
</a>
Please help me to resolve my problem with lxml.
How can I get "Comment 1" from this file?
<?xml version="1.0" encoding="windows-1251" standalone="yes" ?>
<!--Comment 1-->
<a>
<!--Comment 2-->
</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档:lxml 教程,然后搜索“注释”
代码:
输出:
注释:不起作用与 xml.etree.cElementTree
Docs: the lxml tutorial, and search for "Comments"
Code:
Output:
Comments: doesn't work with xml.etree.cElementTree
或者可以肯定的是(可能有多个):
如果您想提取评论的文本,请使用
.text
属性。Or to be sure (there might be more than one):
Use the
.text
attribute if you want to extract the text of the comment.