Java XML Document from String getXmlDocument(final String container)

Here you can find the source of getXmlDocument(final String container)

Description

get Xml Document

License

Open Source License

Parameter

Parameter Description
container a parameter

Exception

Parameter Description
SAXException an exception

Declaration

public static Document getXmlDocument(final String container) throws Exception 

Method Source Code

//package com.java2s;
/*//  ww w  .  j av a 2  s .co  m
 * Fast Code Plugin for Eclipse
 *
 * Copyright (C) 2008  Gautam Dev
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
 *
 * Plugin Home Page: http://fast-code.sourceforge.net/
 */

import java.io.ByteArrayInputStream;

import java.io.InputStream;

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

public class Main {
    /**
     *
     * @param container
     * @return
     * @throws SAXException
     */
    public static Document getXmlDocument(final String container) throws Exception {
        final InputStream inputStream = new ByteArrayInputStream(container.getBytes());

        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        final DocumentBuilder docBuilder = factory.newDocumentBuilder();

        return docBuilder.parse(inputStream);
    }
}

Related

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