解析xml时出错意外令牌(位置:TEXT“结果”

时间:2014-10-17 05:15:26

标签: android xml-parsing

<?xml version='1.0' standalone='yes'?>
    <results>-1</results>

在此处解析此xml代码:

 HttpClient httpclient = new DefaultHttpClient();
                    HttpPost  httppost = new HttpPost(httpurl);
                    try {

                         HttpResponse response = httpclient.execute(httppost);
                         InputStream is = response.getEntity().getContent();
                         WebHelper webHelper = new WebHelper();
                         response1 = webHelper.convertStreamToString(is);

                          XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                             factory.setNamespaceAware(true);
                             XmlPullParser xpp = factory.newPullParser();

                             xpp.setInput(new StringReader (response1));
                             int eventType = xpp.getEventType();
                             while (eventType != XmlPullParser.END_DOCUMENT) {
                              if(eventType == XmlPullParser.START_DOCUMENT) {
                                  System.out.println("Start document");
                              } else if(eventType == XmlPullParser.END_DOCUMENT) {
                                  System.out.println("End document");
                              } else if(eventType == XmlPullParser.START_TAG) {
                                  System.out.println("Start tag "+xpp.getName());
                              } else if(eventType == XmlPullParser.END_TAG) {
                                  System.out.println("End tag "+xpp.getName());
                              } else if(eventType == XmlPullParser.TEXT) {
                                  System.out.println("Text "+xpp.getText());
                              }
                              eventType = xpp.next();
                             }
Getting error:

10-16 20:29:31.529: E/Error:(6077): Unexpected token (position:TEXT "results"
10-16 20:29:31.529: E/Error:(6077): "-1"
10-16 20:29:31.529: E/Error:(6077): @3:1 in java.io.InputStreamReader@421b0660) 
10-16 20:29:31.529: D/AndroidRuntime(6077): Shutting down VM
10-16 20:29:31.529: W/dalvikvm(6077): threadid=1: thread exiting with uncaught exception (group=0x40f01438)

请建议我谢谢

0 个答案:

没有答案