Java Utililty Methods XML Element to String

List of utility methods to do XML Element to String

Description

The list of methods to do XML Element to String are organized into topic(s).

Method

StringtoString(Element xml)
to String
try {
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    StreamResult result = new StreamResult(new StringWriter());
    DOMSource source = new DOMSource(xml);
    transformer.transform(source, result);
    return result.getWriter().toString();
} catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) {
...
StringtoStringNoIndent(Element aElement)
Converts an aElement to a String for printing without pretty printing.
String ret = "ERROR";
ByteArrayOutputStream theBuffer = new ByteArrayOutputStream();
try {
    TransformerFactory transFac = TransformerFactory.newInstance();
    Transformer trans = transFac.newTransformer();
    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    trans.transform(new DOMSource(aElement), new StreamResult(theBuffer));
    theBuffer.close();
...