Java XML Document from String loadDocument(String xmlString)

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

Description

* Load XML document from string ******************************************.

License

Open Source License

Parameter

Parameter Description
xmlString the xml string

Exception

Parameter Description
Exception the exception

Return

the document

Declaration

public static Document loadDocument(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 {
    /**/*from  ww  w .j a v  a  2 s  . c o  m*/
     * *****************************************
     * Load XML document from string
     * ******************************************.
     *
     * @param xmlString the xml string
     * @return the document
     * @throws Exception the exception
     */
    public static Document loadDocument(String xmlString) throws Exception {
        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;
    }
}

Related

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