Here you can find the source of getDocumentFromString(String xmlString)
Parameter | Description |
---|---|
xmlString | the file containing the XML to parse. |
public static Document getDocumentFromString(String xmlString) throws Exception
//package com.java2s; /*--------------------------------------------------------------- * Copyright 2005 by the Radiological Society of North America * * This source software is released under the terms of the * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense) *----------------------------------------------------------------*/ import java.io.*; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.xml.sax.InputSource; public class Main { /**/*from w w w.j av a 2 s. c om*/ * Parses an XML string. * @param xmlString the file containing the XML to parse. * @return the XML DOM document. */ public static Document getDocumentFromString(String xmlString) throws Exception { StringReader sr = new StringReader(xmlString); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); return db.parse(new InputSource(sr)); } }