Java XML Document Create createDocumentFromXml(String input)

Here you can find the source of createDocumentFromXml(String input)

Description

create Document From Xml

License

Open Source License

Declaration

public static Document createDocumentFromXml(String input)
            throws ParserConfigurationException, SAXException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Document createDocumentFromXml(String input)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

        StringReader stringReader = new StringReader(input);
        InputSource inputSource = new InputSource(stringReader);
        return documentBuilder.parse(inputSource);
    }//from w w w .  j  ava 2  s.  co m
}

Related

  1. createDocumentFromElement(final Element element)
  2. createDocumentFromFile(File file)
  3. createDocumentFromResult( final StreamResult result)
  4. createDocumentFromString(String str)
  5. createDocumentFromString(String xmlString)
  6. createDocumentFromXMLContent(String docContent)
  7. createDocumentFromXmlFragment(final InputStream inputStreamXmlFragment, final URL urlSchema)
  8. createDocumentFromXmlString(String xmlStr)
  9. createEmptyDocument()