Java Utililty Methods XML Element from String

List of utility methods to do XML Element from String

Description

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

Method

ElementstringToElement(final String inputXml)
Convert XML string to Element.
try {
    final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    final Document document = builder.parse(new ByteArrayInputStream(inputXml.getBytes("UTF-8")));
    return document.getDocumentElement();
} catch (ParserConfigurationException ex) {
    throw new IOException("IgapyonXmlUtil#stringToElement: Fail to configure xml parser: ", ex);
} catch (SAXException ex) {
    throw new IOException("IgapyonXmlUtil#stringToElement: Fail to process xml: ", ex);
...
ElementstringToElement(String s)
Convert the String representation of an Element into an Element
return stringToElement(s, false);
ElementstringToElement(String xml)
Converts a String representing an XML snippet into an org.w3c.dom.Element .
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document d = builder.parse(bais);
bais.close();
return d.getDocumentElement();