Here you can find the source of loadXMLFromString(String xml)
public static Document loadXMLFromString(String xml)
//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; } } }