List of utility methods to do XML Document Load
Document | documentFrom(InputStream is) document From is = new NamespaceRemovingInputStream(is); Document doc = factory.newDocumentBuilder().parse(is); is.close(); return doc; |
Document | documentFrom(String xml) document From return documentFrom(new ByteArrayInputStream(xml.getBytes())); |
Document | documentFrom(URL url) document From return documentFrom(url.openStream());
|
Document | URLToDocument(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(); ... |
Document | getDocument(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); ... |
Document | getDocument(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); ... |
Document | loadXMLFromString(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) { ... |
Document | load(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) { ... |
XmlPullParser | loadData(String xmlData) load Data XmlPullParserFactory parserFactory = XmlPullParserFactory .newInstance(); XmlPullParser parser = parserFactory.newPullParser(); parser.setInput(new StringReader(xmlData)); return parser; |
Document | loadFile(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); ... |