Link to home
Start Free TrialLog in
Avatar of nikomanek
nikomanekFlag for Afghanistan

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"><WebServiceUrl>http://xxx.xxx.com/rest/xxxx-1.0.php</WebServiceUrl><Success>true</Success></NResultAuthorize>

And I simply don't find a way to get the value "true" out of this string. Any code snipped would be very appreciated...
Avatar of mccarl
mccarl
Flag of Australia image

Are you able to provide us with what you have already tried. It would be a good starting point to helping you out.
Avatar of nikomanek

ASKER

Hi,

I stripped it down to the below...

Button go = (Button) findViewById(R.id.do_action);
        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.newInstance();
                            XmlPullParser parser = parserCreator.newPullParser();

                            parser.setInput(text.openStream(), 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.getAttributeValue(null, "Success"));
                                        
                                        
                                  }
                            }
                               
                                                };

                                     
                               

                                eventType = parser.next();
                                Log.d("","Did not find it");
                           
                           

                        } catch (Exception e) {
                            Log.e("Net", "Error in network call", e);
                        }
            }
});}
}
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.