如何规范 Stax XML 对象
我想规范化一个 Stax 对象,该程序使用 DOM 来实现,但 dom 无法管理大型 XML 文档(如 1GB),所以 STAX 是解决方案。
我的代码是:
File file=new File("big-1gb.xml");
org.apache.xml.security.Init.init();
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dfactory.newDocumentBuilder();
Document doc = documentBuilder.parse(file);
Canonicalizer c14n = Canonicalizer.getInstance("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
outputBytes = c14n.canonicalizeSubtree(doc.getElementsByTagName("SomeTag").item(0));
它的想法是用 Stax 执行下面的代码...
Thx :)
i want to Canonicalize a Stax object, the program it's doing it with DOM, but dom can't manage big XML documents (like 1GB), so STAX it's the solution.
The Code that i have it's:
File file=new File("big-1gb.xml");
org.apache.xml.security.Init.init();
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dfactory.newDocumentBuilder();
Document doc = documentBuilder.parse(file);
Canonicalizer c14n = Canonicalizer.getInstance("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
outputBytes = c14n.canonicalizeSubtree(doc.getElementsByTagName("SomeTag").item(0));
The idea it's do the code below with Stax...
Thx :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用 XOM 库解决了这个问题,这里是等效的代码。
这段代码可以管理200Mb的文件,并且需要7分钟来进行规范化,如果您有疑问,请参阅XOM文档,它非常清晰并且有很多示例。
感谢大家的评论:)
I solve this problem with XOM library, here is the equivalent code.
This code can manage files of 200Mb, and take 7 minutes to do the canonicalization, if you have doubt's, see the XOM documentation, it's pretty clear and have a lot of Examples.
Thx to all for your comments :)