Here you can find the source of stringToDocument(String xmlString)
public static Document stringToDocument(String xmlString) throws IOException, SAXException
//package com.java2s; /*//from w w w . ja v a 2 s . c om * Copyright (C) 2018 Saxon State and University Library Dresden (SLUB) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; public class Main { @SuppressWarnings("CanBeFinal") // initialization happens in static block private static DocumentBuilder db; public static Document stringToDocument(String xmlString) throws IOException, SAXException { return db.parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8"))); } public static Document parse(InputStream inputStream) throws IOException, SAXException { Document doc = db.parse(inputStream); doc.getDocumentElement().normalize(); return doc; } }