Android Utililty Methods XML Parse

List of utility methods to do XML Parse

Description

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

Method

Documentparse(File source)
parse
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
        .newDocumentBuilder();
return builder.parse(source);
Documentparse(String source)
parse
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
        .newDocumentBuilder();
return builder.parse(new ByteArrayInputStream(source.getBytes()));
Tparse(String xml)
parse
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parse = factory.newSAXParser();
return null;
Listparse(String xmlstr, Class clazz, List fields, List elements, String itemElement)
parse
List<Object> list = new ArrayList<Object>();
try {
    XmlPullParser xmlPullParser = Xml.newPullParser();
    xmlPullParser.setInput(new StringReader(xmlstr));
    int event = xmlPullParser.getEventType();
    Object obj = null;
    while (event != XmlPullParser.END_DOCUMENT) {
        switch (event) {
...
DocumentparseResponse(HttpResponse response)
parse Response
InputStream responseStream = response.getEntity().getContent();
DocumentBuilder xmlBuilder = DocumentBuilderFactory.newInstance()
        .newDocumentBuilder();
return xmlBuilder.parse(responseStream);
StringparseTagValue(String xml, String tag, String endTag)
This method parse the xml tag value.
String val = "";
try {
    int index1 = xml.indexOf(tag) + tag.length();
    int index2 = xml.indexOf(endTag, index1);
    if (index1 > -1 && index2 > -1) {
        val = xml.substring(index1, index2);
} catch (Throwable thrown) {
...
StringReadCityCode(Context context, String cityname)
Read City Code
String returnString = "";
DocumentBuilderFactory docBuilderFactory = null;
DocumentBuilder docBuilder = null;
Document doc = null;
try {
    docBuilderFactory = DocumentBuilderFactory.newInstance();
    docBuilder = docBuilderFactory.newDocumentBuilder();
    doc = docBuilder.parse(context.getAssets().open("citys.xml"));
...
DocumentXMLfromString(String xml)
XM Lfrom String
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
    dbf.setCoalescing(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    doc = db.parse(is);
...