Is there a more elegant way to convert an XML Document to a String in Java than this code?

Relies on DOM Level3 Load/Save:

public String getStringFromDoc(org.w3c.dom.Document doc)    {
    DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
    LSSerializer lsSerializer = domImplementation.createLSSerializer();
    return lsSerializer.writeToString(doc);   
}

Leave a Comment