在 Python 中,我需要规范化 (c14n) XML 字符串。
我可以使用哪个模块/包来实现此目的?我应该怎么做?
(我更喜欢使用默认的 python 2.7 模块,无需额外安装或补丁。)
参考见:http://www.w3.org/TR/xml-exc-c14n/ http://www.w3.org/TR/xml-exc-c14n/
from http://www.decalage.info/en/python/lxml-c14n http://www.decalage.info/en/python/lxml-c14n
lxml http://lxml.de/提供了一种在 python 中执行 c14n 的非常简单的方法。
<..>
以下示例展示了如何使用 lxml 2.1 执行 C14N:
import lxml.etree as ET
et = ET.parse('file.xml')
output = StringIO.StringIO()
et.write_c14n(output)
print output.getvalue()
来自 lxml 文档:
写_c14n http://lxml.de/api/lxml.etree._ElementTree-class.html#write_c14n(自身、文件、独占=假, with_comments=True,
压缩=0,inclusion_ns_prefixes=无)
C14N 编写文档。始终写入 UTF-8。
还有libxml2:
XML C14N 1.0 版提供了两个选项,这使得四个选项
可能性(参见http://www.w3.org/TR/xml-c14n http://www.w3.org/TR/xml-c14n and
http://www.w3.org/TR/xml-exc-c14n/ http://www.w3.org/TR/xml-exc-c14n/):
libxml2 允许在其 C14N API 中访问这些选项:http://xmlsoft.org/html/libxml-c14n.html http://xmlsoft.org/html/libxml-c14n.html
尽管必须检查这两个库中的版本更改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)