Java XML Document from String loadXMLFromString(String xml)

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

Description

load XML From String

License

Open Source License

Declaration

public static Document loadXMLFromString(String xml) 

Method Source Code

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

import java.io.ByteArrayInputStream;

import org.w3c.dom.*;

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

public class Main {
    public static Document loadXMLFromString(String xml) {
        try {/*w  w  w. j  a  va2  s.c  o m*/
            DocumentBuilderFactory factory = DocumentBuilderFactory
                    .newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new ByteArrayInputStream(xml
                    .getBytes("UTF-8")));
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. loadDocument(String xmlString)
  2. loadXml(String xml)
  3. loadXMLFrom(String xml)
  4. loadXMLFromString(String xml)
  5. loadXMLFromString(String xml)
  6. readString(String xml)