在 XMLPullParser 中始终获取 0,而 Web 服务包含的值为 float
我有一个用于评级的网络服务,它返回
,而使用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>
任何人都可以告诉我这段代码有什么问题吗?
I have a webservice for rating it return <Score>float</Score>
while retrieving this using XML parser always return null[0]. I don't have any idea. My code is below:
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;
}
My Web service xml is :
<?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>
Can any body tell me what is wrong with this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论