Java:XML 规范化
在 Java 中制作规范形式的 XML 文件的最简单方法是什么?你有一些完成的代码吗?我在网上找到了几个链接,例如 这个,这个,以及这个,但我无法让它工作:/
谢谢,
伊万
编辑:我使用了那里提出的规范化器,但我得到了奇怪的结果。更准确地说,此方法不会删除元素之间的空格...这就是我得到的:
<Metric xmlns="http://www.ibm.com/wsla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="total_memory_consumption_metric" type="double" unit="Mbit" xsi:schemaLocation="http://www.ibm.com/wsla WSLA.xsd"> <Source>ServiceProvider</Source> <MeasurementDirective resultType="double" xsi:type="StatusRequest"> <RequestURI> ***unused*** </RequestURI> </MeasurementDirective> </Metric>
What's the easiest way to make a canonical form of a XML file in Java? Do you have some done code for that? I've found several links on the net, like this, this, and this, but I can't make it to work :/
Thanks,
Ivan
EDIT: I used the canonicalizer that was proposed down there, but I get strange results. To be more precize, this method doesn't delete white spaces between elements... This is what I get:
<Metric xmlns="http://www.ibm.com/wsla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="total_memory_consumption_metric" type="double" unit="Mbit" xsi:schemaLocation="http://www.ibm.com/wsla WSLA.xsd"> <Source>ServiceProvider</Source> <MeasurementDirective resultType="double" xsi:type="StatusRequest"> <RequestURI> ***unused*** </RequestURI> </MeasurementDirective> </Metric>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Canonicalizer 类位于 Apache XML 安全项目。
初始化库。
转换您的 XML。
The Canonicalizer class at Apache XML Security project.
Initialize the library.
Convert your XML.
另一个选择是 nu.xom.canonical.Canonicalizer 如果您正在使用 XOM,或者如果您不需要 Apache XML 安全性。
Another option is nu.xom.canonical.Canonicalizer if you're using XOM, or if you don't otherwise have a need for Apache XML Security.