Android XML Document Create LoadXml(String xml)

Here you can find the source of LoadXml(String xml)

Description

Load Xml

Declaration

public static Document LoadXml(String xml) throws Exception 

Method Source Code

//package com.java2s;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

public class Main {
    public static Document LoadXml(String xml) throws Exception {
        // create...
        ByteArrayInputStream stream = new ByteArrayInputStream(
                xml.getBytes());/*w  w  w .j  a v  a2s.  co m*/
        try {
            return LoadXml(stream);
        } finally {
            if (stream != null)
                stream.close();
        }
    }

    private static Document LoadXml(InputStream stream) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();
        factory.setNamespaceAware(true);

        // builder...
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(stream);

        // return...
        return doc;
    }
}

Related

  1. createDocument(final String source, boolean isNamespaceAware)
  2. createXml(Document document)
  3. getOrCreateElement(Document doc, Element manifestElement, String elementName)
  4. getDomElement(File xmlFile)
  5. getDomElement(String aXml)