Here you can find the source of stringToDoc(String s, boolean nameSpaceAware)
public static Document stringToDoc(String s, boolean nameSpaceAware) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; /*/*from ww w .j ava 2 s . c om*/ Copyright (c) 2009-2011, AOL Inc. All rights reserved. This code is licensed under a BSD license. */ import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { /** /* Parse an XML string into a DOM document */ public static Document stringToDoc(String s, boolean nameSpaceAware) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(nameSpaceAware); DocumentBuilder docBuilder = domFactory.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(s)); Document doc = docBuilder.parse(is); return doc; } }