我有一个带有 xml 内容的字符串,例如:
String str = "<history><message from="Alice" to="Bob" /></history>";
我想将此 xml 内容添加到某个元素 (org.dom4j.DOMElement)。
怎么做?
我试过这个:
myElement.addText(str);
但它给了我刚刚转义的文本内容。
最佳答案
您需要使用 Dom4j 将 XML 片段解析为单独的 Document 对象,然后将该 Document 对象的根元素附加到目标 Document 的适当位置。
关于java - 将 xml 从 String 添加到 DOMElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6789058/