ProAnswers.org

In Java how can you convert a String that represents a fragment of XML?

In Java how can you convert a String that represents a fragment of XML for insertion into an XML document?

String newNode = “value”; // Convert this to XML
Then insert this node into an org.w3c.dom.Document as the child of a given node?

Element node = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(“value”.getBytes()))
.getDocumentElement();