Android XML Document Load loadXMLFromString(String xml)

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

Description

load XML From String

License

Apache License

Declaration

public static Document loadXMLFromString(String xml) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import android.util.Log;

public class Main {
    public static Document loadXMLFromString(String xml) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();//www  . j a va 2 s . c  om
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc;
        try {
            doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
        } catch (SAXException e) {
            Log.i("XmlHelper", "Parse error.", e);
            doc = null;
        } catch (NullPointerException e) {
            Log.i("XmlHelper", "Parse error. String must not be null.", e);
            doc = null;
        }
        return doc;
    }
}

Related

  1. documentFrom(String xml)
  2. documentFrom(URL url)
  3. URLToDocument(URL url)
  4. getDocument(String strxml)
  5. getDocument(String strxml)
  6. load(String filename)
  7. loadData(String xmlData)
  8. loadFile(Context context, String fileName)