Java XML Document from String loadXml(String xml)

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

Description

load Xml

License

Apache License

Declaration

public static Document loadXml(String xml) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

public class Main {
    public static Document loadXml(String xml) {
        InputSource inputSource = new InputSource(new StringReader(xml));
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {//  w w w  .j av  a2s .c o m
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(inputSource);
            return doc;
        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage(), ex);
        }
    }
}

Related

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