Java Utililty Methods XML Document from String

List of utility methods to do XML Document from String

Description

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

Method

DocumentloadDocument(String xmlString)
* Load XML document from string ******************************************.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource source = new InputSource(new StringReader(xmlString));
Document doc = db.parse(source);
return doc;
DocumentloadXml(String xml)
load Xml
InputSource inputSource = new InputSource(new StringReader(xml));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(inputSource);
    return doc;
} catch (Exception ex) {
    throw new RuntimeException(ex.getMessage(), ex);
...
org.w3c.dom.DocumentloadXMLFrom(String xml)
load XML From
return loadXMLFrom(new java.io.ByteArrayInputStream(xml.getBytes()));
DocumentloadXMLFromString(String xml)
load XML From String
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
return builder.parse(is);
DocumentloadXMLFromString(String xml)
load XML From String
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
} catch (Exception e) {
    return null;
DocumentloadXMLFromString(String xml)
Build Document from String which contains XML content.
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xml));
    return builder.parse(is);
} catch (ParserConfigurationException | SAXException | IOException e) {
return null;
...
DocumentreadString(String xml)
read String
ensureFactory();
try {
    DocumentBuilder builder = mFactory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
} catch (Exception e) {
    if (e instanceof SAXParseException) {
        SAXParseException spe = (SAXParseException) e;
        int l = spe.getLineNumber();
...