Here you can find the source of parseXMLDocument(String xml)
Parameter | Description |
---|---|
xml | The xml string fragment |
public static Document parseXMLDocument(String xml)
//package com.java2s; /***************************************************************************** * Copyright Yumetech, Inc (c) 2006 * Java Source * * This source is licensed under the GNU LGPL v2.1 * Please read http://www.gnu.org/copyleft/lgpl.html for more information * * This software comes with the standard NO WARRANTY disclaimer for any * purpose. Use it at your own risk. If there's a problem you get to fix it. * ****************************************************************************/ import java.io.*; import org.w3c.dom.*; import org.xml.sax.InputSource; import javax.xml.parsers.*; public class Main { /**/* w w w . j a va 2s . com*/ * Parse an XML string into a document. * * @param xml The xml string fragment * @return The parsed XML */ public static Document parseXMLDocument(String xml) { StringReader sr = new StringReader(xml); DocumentBuilderFactory builderFactory; DocumentBuilder builder; try { builderFactory = DocumentBuilderFactory.newInstance(); builder = builderFactory.newDocumentBuilder(); } catch (Exception e) { e.printStackTrace(); return null; } try { Document document = builder.parse(new InputSource(sr)); return document; } catch (FileNotFoundException fnfe) { } catch (Exception e) { e.printStackTrace(); } return null; } }