nikomanek
asked on
How do I use xmlpullparser
Hi there,
I am trying all day long to get a grasp about XmlPullParser. I just have to parse files like:
<?xml version="1.0" encoding="utf-8"?>
<NResultAuthorize xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><WebServiceUr l>http://xxx.xxx.com/rest/xxxx-1.0.php</WebSer viceUrl><S uccess>tru e</Success ></NResult Authorize>
And I simply don't find a way to get the value "true" out of this string. Any code snipped would be very appreciated...
I am trying all day long to get a grasp about XmlPullParser. I just have to parse files like:
<?xml version="1.0" encoding="utf-8"?>
<NResultAuthorize xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><WebServiceUr
And I simply don't find a way to get the value "true" out of this string. Any code snipped would be very appreciated...
Are you able to provide us with what you have already tried. It would be a good starting point to helping you out.
ASKER
Hi,
I stripped it down to the below...
Button go = (Button) findViewById(R.id.do_actio n);
go.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
URL text = new URL("http://xx.xx.xx.210/REST/Service.php?method=XMLAuthorize&username=john&password=pass&type=XML");
XmlPullParserFactory parserCreator = XmlPullParserFactory.newIn stance();
XmlPullParser parser = parserCreator.newPullParse r();
parser.setInput(text.openS tream(), null);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT ) {
if (eventType ==XmlResourceParser.TEXT){
Log.d("", "Document Start");
String strName = parser.getName();
if (strName.equals("Success") ){
Log.d("","Found SUCCESS tag");
Log.d("","The authvalue SUCCESS is"+parser.getAttributeVal ue(null, "Success"));
}
}
};
eventType = parser.next();
Log.d("","Did not find it");
} catch (Exception e) {
Log.e("Net", "Error in network call", e);
}
}
});}
}
I stripped it down to the below...
Button go = (Button) findViewById(R.id.do_actio
go.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
URL text = new URL("http://xx.xx.xx.210/REST/Service.php?method=XMLAuthorize&username=john&password=pass&type=XML");
XmlPullParserFactory parserCreator = XmlPullParserFactory.newIn
XmlPullParser parser = parserCreator.newPullParse
parser.setInput(text.openS
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT
if (eventType ==XmlResourceParser.TEXT){
Log.d("", "Document Start");
String strName = parser.getName();
if (strName.equals("Success")
Log.d("","Found SUCCESS tag");
Log.d("","The authvalue SUCCESS is"+parser.getAttributeVal
}
}
};
eventType = parser.next();
Log.d("","Did not find it");
} catch (Exception e) {
Log.e("Net", "Error in network call", e);
}
}
});}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mccarl is my personal hero now:-) I was playing around with that an entire day being new to Java etc. This really saved my sanity.