This is XML URL
http://www.eboundservices.com/distribution/vod_new.xml
How we Parse in Android
<Aajkamrankhankaysath p0201="" p0801="" p0901="" p1501="" p1601="" p2201="" p2301="" p2901="" p3001="" p0702="" p2102="" p0303="" p0403="" p0603="" p1003="" p1103="" p1203="" p1303="" p1703="" p1803="" p1903="" p2003="" p2403="" p2503="" p2603="" p2703="" p2803="" p3103="" p0104="" p0204="" p0304="" p0404="" p0704="" p0804="" p0904="" p1004="" p1104="" p1404="" p1504="" p1604="" p1704="" p1804="" p2104="" p2204="" p2304="" p2404="" p2804="" p2904="" p3004="" p0105="" p0205="" p0505="" p0605="" p0705="" p0805="" p0905="" p1205="" p1305="" p1405="" p1505="" p1605="" p1905="" p2005="" p2105="" p2205="" p2305="" p2705="" p2805="" p2905="" p3005="" p0206="" p0306="" p0406="" p0506="" p2306="" p2406="" p2506="">25</Aajkamrankhankaysath>
I want to get like: p0201, p0801, p0901, p1501, p1501... and So On
I want to save in ArrayList, mean A TAG <> data in a AaaryList Respectively
First of all these are attributes as someone has already mentioned. It is certainly a bad idea to have such a badly formed XML, even if the web-service is big I can see it's being developed in a very bad manner. Personal opinions aside, you will need to create your own class in order to populate a list of objects. You will need to read through every node, and populate every attribute manually and no short cut will work(as far as I know).
public class TVNode {
String p0210;
String p0801;
String p0901;
// so on an so forth, define String mmembers for every attribute
public TVNode()
{
}
public void setp0210(String _p0210)
{
}
public void setp0801(String _p0801)
{
}
public void setp0901(String _p0901)
{
}
// and getters too of course
}
You'll have a list of TVNode type, you'll read the XML from either a file or web-response and once you have it you'll need to parse it using some type of XMLDOMParser. I hope this helps.
xmlpullparser is faster than loading a document. It is exactly suited for the xml example you have in your question.
XmlPullParser xpp;
XmlPullParserFactory factory = null;
factory = XmlPullParserFactory.newInstance();
xpp = factory.newPullParser();
xpp.setInput(kmlis, "UTF-8"); //todo get your input into inputstream
int eventType = xpp.getEventType();
while (true) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equals("aajdsaklhandsksplsb")){
int x = xpp.getAttributeCount();
for (int i = 0;i<x;i++){
String name = xpp.getAttributeName(i);
String value = xpp.getAttributeValue(i)
log.d("test", name + "=" + value);
}
}
}
else if (eventType == XmlPullParser.END_DOCUMENT) {break;}
eventType = xpp.getEventType();
}
That has to be the worst format XML, there a some other parser like XMLPullParser, DOMParser and SAXParser but you can use xmlPullParser to get attribute values according to your requirements.
Here is sample xml:
<message id="abc@web.hightech.com" from="web.hightect.com" text="Hello World">
<firstname>Marie Josèphe</firstname>
<lastname>Joseph</lastname>
</message>
Here is a complete Parser and you can use this generic parser to fulfill your requirement Example: You can to get id and text from first attribute
public class New_Generic_Parser {
public static ArrayList<String> list = new ArrayList<String>();
XmlPullParserFactory xmlFactoryObject = null;
String payload,option_text1,option_text2;
public New_Generic_Parser() {
payload = "";
list = new ArrayList<String>();
option_text1 = "";
option_text2 = "";
}
private void parseXMLAndStoreIt(XmlPullParser myParser) {
int event;
try {
event = myParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
String name=myParser.getName();
switch (event){
case XmlPullParser.START_TAG:
if(name.equalsIgnoreCase("user")){
option_text1 = myParser.getAttributeValue(null, "id");
option_text2 = myParser.getAttributeValue(null,"text");
//get attribute from here:
}
break;
case XmlPullParser.TEXT:
if(name.equalsIgnoreCase("user")){
list.add(myParser.getText());
}
break;
case XmlPullParser.END_TAG:
String pic = list.get(0).toString();
byte [] encodeByte=Base64.decode(pic,Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
break;
}
event = myParser.next();
}
// parsingComplete = false;
} catch (Exception e) {
e.printStackTrace();
}
}
public void genericparser(String payload){
try {
InputStream stream = new ByteArrayInputStream(payload.getBytes());
xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myparser = xmlFactoryObject.newPullParser();
myparser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
myparser.setInput(stream, null);
parseXMLAndStoreIt(myparser);
stream.close();
} catch (Exception e) {
// TODO: handle exception
}
}