Java XML Document from String getDocumentFromString(String xmlString)

Here you can find the source of getDocumentFromString(String xmlString)

Description

Parses an XML string.

License

Open Source License

Parameter

Parameter Description
xmlString the file containing the XML to parse.

Return

the XML DOM document.

Declaration

public static Document getDocumentFromString(String xmlString) throws Exception 

Method Source Code


//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2005 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

import java.io.*;

import org.w3c.dom.Document;

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

import org.xml.sax.InputSource;

public class Main {
    /**/*from   w  w w.j av  a  2 s. c om*/
     * Parses an XML string.
     * @param xmlString the file containing the XML to parse.
     * @return the XML DOM document.
     */
    public static Document getDocumentFromString(String xmlString) throws Exception {
        StringReader sr = new StringReader(xmlString);
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return db.parse(new InputSource(sr));
    }
}

Related

  1. getDocumentFromBytes(byte[] data)
  2. getDocumentFromString(String text)
  3. getDocumentFromString(String xml)
  4. getDocumentFromString(String xml)
  5. getDocumentFromString(String xml)
  6. getDocumentFromString(String xmlString)
  7. getXmlDocument(final String container)
  8. getXMLDocument(final String xml)
  9. loadDocument(String documentContent)