Android Utililty Methods XML Document Load

List of utility methods to do XML Document Load

Description

The list of methods to do XML Document Load are organized into topic(s).

Method

DocumentdocumentFrom(InputStream is)
document From
is = new NamespaceRemovingInputStream(is);
Document doc = factory.newDocumentBuilder().parse(is);
is.close();
return doc;
DocumentdocumentFrom(String xml)
document From
return documentFrom(new ByteArrayInputStream(xml.getBytes()));
DocumentdocumentFrom(URL url)
document From
return documentFrom(url.openStream());
DocumentURLToDocument(URL url)
URL To Document
URLConnection urlconn = url.openConnection();
urlconn.setUseCaches(false);
InputStream istr = urlconn.getInputStream();
Document doc = null;
try {
    doc = InputStreamToDocument(istr);
} finally {
    istr.close();
...
DocumentgetDocument(String strxml)
get Document
DocumentBuilderFactory factory = DocumentBuilderFactory
        .newInstance();
try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    strxml = new String(strxml.getBytes(), "UTF-8");
    StringReader stringReader = new StringReader(strxml);
    InputSource inputSource = new InputSource(stringReader);
    Document document = builder.parse(inputSource);
...
DocumentgetDocument(String strxml)
get Document
DocumentBuilderFactory factory = DocumentBuilderFactory
        .newInstance();
try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    strxml = new String(strxml.getBytes(), "UTF-8");
    StringReader stringReader = new StringReader(strxml);
    InputSource inputSource = new InputSource(stringReader);
    Document document = builder.parse(inputSource);
...
DocumentloadXMLFromString(String xml)
load XML From String
DocumentBuilderFactory factory = DocumentBuilderFactory
        .newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc;
try {
    doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
} catch (SAXException e) {
...
Documentload(String filename)
load
Document document = null;
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory
            .newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse(new File(filename));
    document.normalize();
} catch (Exception ex) {
...
XmlPullParserloadData(String xmlData)
load Data
XmlPullParserFactory parserFactory = XmlPullParserFactory
        .newInstance();
XmlPullParser parser = parserFactory.newPullParser();
parser.setInput(new StringReader(xmlData));
return parser;
DocumentloadFile(Context context, String fileName)
load File
File cacheDir = context.getCacheDir();
File file = new File(cacheDir, fileName);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document document = null;
try {
    db = dbf.newDocumentBuilder();
    document = db.parse(file);
...