Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有 xml 内容的字符串,例如:
String str = "<history><message from="Alice" to="Bob" /></history>";
我想将此 xml 内容添加到某个元素(org.dom4j.DOMElement)。怎么做? 我试过这个:
myElement.addText(str);
但它给了我只是转义的文本内容。
您需要使用 Dom4j 将 XML 片段解析为单独的 Document 对象,然后将该 Document 对象的根元素附加到目标 Document 的适当位置。