简体   繁体   English

如何以编程方式修改XML文档以遵守Java中的DTD

[英]How can I programatically modify an XML Document to respect a DTD in java

I have an XML Document built programatically and waiting for serialisation (as a String ). 我已经以编程方式构建了XML文档,并等待序列化(作为String )。 Before serialising it though, I would like to re-arrange its nodes so that they match the definition of the DTD. 在序列化它之前,我想重新排列其节点,使其与DTD的定义匹配。 I should mention that my implementation prevents me to know in which order the tree will be built. 我应该提到的是,我的实现使我无法知道树的构建顺序。

Any recommended solutions for this ? 有什么推荐的解决方案吗?

There is some academic research to correct invalid XML: 有一些学术研究可以纠正无效的XML:

Correction of Invalid XML Documents with Respect to Single Type Tree Grammars 关于单类型树语法的无效XML文档的更正

but I don't know if there is any available library for that. 但我不知道是否有任何可用的库。

So you need to do it by hand, or better rework the generation of the document so that it produces a valid instance in the first place. 因此,您需要手动执行此操作,或者更好地重做文档的生成,以便首先生成有效的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM