Here you can find the source of stringToDocument(String string)
public static Document stringToDocument(String string) throws SAXException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Gabriel Skantze./* ww w . j a va 2 s . c om*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Gabriel Skantze - initial API and implementation ******************************************************************************/ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { public static Document stringToDocument(String string) throws SAXException, IOException { return getBuilder().parse( new ByteArrayInputStream(string.getBytes())); } public static Document parse(File file) throws SAXException, IOException { return getBuilder().parse(file); } public static DocumentBuilder getBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); try { return dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; } }