Java XML String to Document toDocument(String s)

Here you can find the source of toDocument(String s)

Description

to Document

License

Open Source License

Declaration

public static Document toDocument(String s)
            throws IOException, org.xml.sax.SAXException, ParserConfigurationException 

Method Source Code

//package com.java2s;
/**//w  ww .  ja  v  a2 s . com
 * Copyright (c) 2007-2008. MB Software Vancouver, Canada. All Rights Reserved.
 * This software is published under the GPL GNU General Public License. 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version.
 *  
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 * 
 * This software was written for 
 * MB Software, margaritabowl.com
 * Vancouver, B.C., Canada 
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.SAXException;

public class Main {
    public static Document toDocument(String s)
            throws IOException, org.xml.sax.SAXException, ParserConfigurationException {
        return (toDocument(s.getBytes()));
    }

    public static Document toDocument(byte[] x)
            throws IOException, org.xml.sax.SAXException, ParserConfigurationException {
        ByteArrayInputStream is = new ByteArrayInputStream(x, 0, x.length);
        return (toDocument(is));
    }

    public static Document toDocument(InputStream is)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(is);
        return (document);
    }
}

Related

  1. strToDocument(final String strXml)
  2. strToXML(final Document doc, final String namespaceURI, final String qname, final String str)
  3. toDocument(String content)
  4. toDocument(String input)
  5. toDocument(String str)
  6. toDocument(String string)
  7. toDocument(String xml)
  8. toDocument(String xml)