在XMLPullParser中总是0,而webservice包含值为float

时间:2011-05-09 17:18:08

标签: android web-services xmlpullparser

我有一个web服务来评级它返回<Score>float</Score>,而使用XML解析器检索它总是返回null [0]。我什么都不知道。我的代码如下:

public static String parse(InputStream is) 
        {
            XmlPullParserFactory factory = null;
            try {
                factory = XmlPullParserFactory.newInstance();
            } catch (XmlPullParserException e1) {
                // TODO Auto-generated catch block
                Log.v(TAG,"Exception in Factory pull");
            }

            factory.setNamespaceAware(true);

            XmlPullParser parser = null;

            try {
                parser = factory.newPullParser();
            } catch (XmlPullParserException e1) {
                Log.v(TAG,"Exception in parser pull");
            }

            String rating = "";
            //XmlPullParser parser = Xml.newPullParser();
            Log.v("XMLParser:", parser.toString());
            try 
            {
                // auto-detect the encoding from the stream
                parser.setInput(is, null);
                int eventType = parser.getEventType();
                //Message currentMessage = null;
                boolean done = false;
                while (eventType != XmlPullParser.END_DOCUMENT && !done)
                {
                    String name = null;
                    switch (eventType)
                    {
                        case XmlPullParser.START_DOCUMENT:
                            break;
                        case XmlPullParser.START_TAG:
                            name = parser.getName();
                            if (name.equalsIgnoreCase("Score"))
                            {
                                rating = parser.nextText();
                                Log.v("Rating", rating);
                                done = true;
                            }   
                            break;
                        case XmlPullParser.TEXT:
                            Log.v(TAG,"Node value:"+parser.getText());
                        case XmlPullParser.END_TAG:
                            break;
                    }
                    eventType = parser.next();
                }
            } 
            catch (Exception e) 
            {
                rating = "0";
            }
            return rating;

        }

我的Web服务xml是:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetRatingDResponse xmlns="http://tempuri.org/">
      <GetRatingDResult>
        <Votes>int</Votes>
        <Score>float</Score>
      </GetRatingDResult>
    </GetRatingDResponse>
  </soap:Body>
</soap:Envelope>

任何机构都可以告诉我这段代码有什么问题吗?

0 个答案:

没有答案