Java XML Document from String getDocumentFromString(String xmlString)

Here you can find the source of getDocumentFromString(String xmlString)

Description

get Document From String

License

Open Source License

Declaration

public static Document getDocumentFromString(String xmlString) throws Exception 

Method Source Code


//package com.java2s;

import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class Main {
    public static Document getDocumentFromString(String xmlString) throws Exception {
        DocumentBuilderFactory oDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
        try {/*w w w  . j a v a 2s.  co  m*/
            // Do not load the DTD
            oDocumentBuilderFactory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd",
                    Boolean.FALSE);
        } catch (IllegalArgumentException e) {
        }
        DocumentBuilder oDocumentBuilder = oDocumentBuilderFactory.newDocumentBuilder();

        InputSource inputSource = new InputSource(new StringReader(xmlString));
        return oDocumentBuilder.parse(inputSource);
    }
}

Related

  1. getDocumentFromString(String text)
  2. getDocumentFromString(String xml)
  3. getDocumentFromString(String xml)
  4. getDocumentFromString(String xml)
  5. getDocumentFromString(String xmlString)
  6. getXmlDocument(final String container)
  7. getXMLDocument(final String xml)
  8. loadDocument(String documentContent)
  9. loadDocument(String xmlString)