Java XML Document Create getDocument(String xml)

Here you can find the source of getDocument(String xml)

Description

get Document

License

Open Source License

Declaration

private static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException 

Method Source Code

//package com.java2s;
/**//from  ww w  .  j  a v a  2  s  .c o  m
 * Copyright (C) 2010-2012 Barcelona Supercomputing Center
 *
 * This library is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.io.IOException;
import java.io.StringReader;
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 {
    private static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException {
        // Create a builder factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);

        return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
    }
}

Related

  1. getDocument(Resource resource)
  2. getDocument(String docPath)
  3. getDocument(String fileName)
  4. getDocument(String filePath)
  5. getDocument(String payload)
  6. getDocument(String xml)
  7. getDocument(String xmlDocument)
  8. getDocument(String xslName)
  9. getDocument(URL location, boolean validating, boolean namespaceAware)