Java XML Document Create stringToDocument(String xmlStr, boolean isValidating)

Here you can find the source of stringToDocument(String xmlStr, boolean isValidating)

Description

string To Document

License

Mozilla Public License

Declaration

public static Document stringToDocument(String xmlStr, boolean isValidating)
            throws SAXException, IOException, ParserConfigurationException 

Method Source Code


//package com.java2s;
//License from project: Mozilla Public License 

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    public static Document stringToDocument(String xmlStr, boolean isValidating)
            throws SAXException, IOException, ParserConfigurationException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(isValidating);
        DocumentBuilder builder = factory.newDocumentBuilder();

        InputSource inputSource = new InputSource(new StringReader(xmlStr));
        Document document = builder.parse(inputSource);
        return document;
    }//from w  w  w. j  a  v  a 2 s .c  om
}

Related

  1. stringToDocument(String doc)
  2. stringToDocument(String string)
  3. stringToDocument(String string)
  4. stringToDocument(String string)
  5. stringToDocument(String xml)
  6. stringToDocument(String xmlString)
  7. toDocument(File f)
  8. toDocument(Reader reader)
  9. toDocument(ResultSet rs)