java中如何将一个xml文档添加到另一个xml文档中

发布于 2024-09-05 17:43:07 字数 281 浏览 1 评论 0原文

我有一个像这样的 xml 文档 rootXMLDoc=; <参数> 。我需要插入 paramxmlDoc= abc。如何在java中将paramxmlDoc插入rootXMLDoc?我需要这样的输出 <代码><根目录> <参数par='1'>abc <参数>

I have a xml document like this rootXMLDoc=<root> <param></param></root> . I need to insert paramxmlDoc= <parameter par='1'>abc</parameter>. how to insert paramxmlDoc to rootXMLDoc in java.? and i need output like this
<root>
<parameter par='1'>abc</parameter>
<param></param>
</root>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花期渐远 2024-09-12 17:43:07

像这样:

Element e = paramxmlDoc.getRootElement();
paramxmlDoc.setRootElement(null); // break connection between doc and element
rootXMLDoc.getRootElement().addChild(e); // Insert node in other document

注意:这是从记忆中得出的,因此实际的方法调用可能略有不同,但您明白了。

Like this:

Element e = paramxmlDoc.getRootElement();
paramxmlDoc.setRootElement(null); // break connection between doc and element
rootXMLDoc.getRootElement().addChild(e); // Insert node in other document

Note: This is from memory, so the actual method calls can be slightly different but you get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文