Adadiaminna
New Member
Im new in Android development. I have a task to parse XML from current url http://belbooner.site40.net/testXmls/details.xmlI made a class to make it possible\[code\] package com.example.asd;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.StringReader;import java.ibjectOutputStream.PutField;import java.net.HttpURLConnection;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.xml.parsers.ParserConfigurationException;import org.xml.sax.SAXException;import org.xmlpull.v1.*;import android.renderscript.Sampler.Value;import android.util.Log;import android.widget.TextView;public class RequestResponse extends Thread { // HTTP request, get xml file void getXml() throws ParserConfigurationException, IOException, SAXException, XmlPullParserException { URL url= new URL("http://belbooner.site40.net/testXmls/details.xml"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("ACCEPT","application/xml"); conn.connect(); InputStream streamer = conn.getInputStream(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp= factory.newPullParser(); factory.setNamespaceAware(true); xpp.setInput(streamer,null); String targetValue = http://stackoverflow.com/questions/13779009/null; ArrayList<HashMap<String, String>> checkArr= new ArrayList<HashMap<String,String>>(); ArrayList<String> checkIDarr = getChecks(xpp,"check", "checkid", targetValue); ArrayList<String> dsc_247arr = getChecks(xpp, "check","dsc_247" , targetValue); ArrayList<String> descriptionArr = getChecks(xpp, "check", "description", targetValue); ArrayList<String> extra = getChecks(xpp, "check", "extra", targetValue); ArrayList<String> datetime = getChecks(xpp, "check", "datetime", targetValue); ArrayList<String> consecutive_fails = getChecks(xpp, "check", "consecutive_fails", targetValue); ArrayList<String> emailalerts = getChecks(xpp, "check", "emailalerts", targetValue); } void getServerInfo(XmlPullParser xpp) throws XmlPullParserException, IOException { } ArrayList<String> getChecks(XmlPullParser xpp,String targetTag,String checkedTag,String targetValue) throws XmlPullParserException, IOException, NullPointerException { ArrayList<String> tagValueArray= new ArrayList<String>(); Map<String, String> checkedMap= new HashMap<String, String>(); int eventType=xpp.getEventType(); while(xpp.getEventType() != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_DOCUMENT) { } else if(eventType == XmlPullParser.END_DOCUMENT) { } else if(eventType == XmlPullParser.START_TAG) { if(xpp.getName().equals(targetTag)){ xpp.next(); } if(xpp.getName().equals(checkedTag)) { targetValue = http://stackoverflow.com/questions/13779009/xpp.nextText(); tagValueArray.add(targetValue); checkedMap.put(checkedTag, targetValue); Log.e(checkedTag, targetValue); } // System.out.println("Start tag "+xpp.getName()); } else if(eventType == XmlPullParser.END_TAG) { } else if(eventType == XmlPullParser.TEXT) { } eventType = xpp.next(); } return tagValueArray; } void getOutages() { } void getNotes() { } void getCheck() { }}\[/code\]While trying to get values from all checkid nodes in XML file with this call\[code\]ArrayList<String> checkIDarr = getChecks(xpp, "check", "checkid", targetValue);\[/code\]i can get them all, but other commands like\[code\]ArrayList<String> dsc_247arr = getChecks(xpp, "check","dsc_247" , targetValue);\[/code\]are not giving any result, but if i delete all commands an leave \[code\]ArrayList<String> dsc_247arr\[/code\] it will work, so my cuestion is how to make all command work. Thank you.