Android XML Document Create getDomElement(String aXml)

Here you can find the source of getDomElement(String aXml)

Description

Gets DOM structure

Parameter

Parameter Description
aXml XML string

Return

DOM structure

Declaration

public static Document getDomElement(String aXml) 

Method Source Code

//package com.java2s;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    /**/*from www.  jav  a2  s.  c  o  m*/
     * Gets DOM structure
     * 
     * @param aXml
     *            XML string
     * @return DOM structure
     */
    public static Document getDomElement(String aXml) {
        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {

            DocumentBuilder db = dbf.newDocumentBuilder();

            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(aXml));
            doc = db.parse(is);

        } catch (ParserConfigurationException e) {
            return null;
        } catch (SAXException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
        // return DOM
        return doc;
    }
}

Related

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