Java XML DOM from String stringToDOM(String xmlString)

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

Description

string To DOM

License

Open Source License

Declaration

public static Document stringToDOM(String xmlString) 

Method Source Code


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

import org.w3c.dom.Document;
import org.xml.sax.InputSource;

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

import java.io.*;

public class Main {
    public static Document stringToDOM(String xmlString) {
        try {/*from   w  w  w  .j  av  a2 s  . c om*/
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new InputSource(new StringReader(xmlString)));
        } catch (Throwable t) {
            throw new RuntimeException("Error while building document");
        }
    }
}

Related

  1. string2Dom(final String fileContent)
  2. string2Dom(String xml)
  3. stringToDOM(String html)
  4. stringToDom(String xmlSource)
  5. stringToDOM(String xmlString)