我正在使用 XmlPullParser 尝试SOAP解析xml。但是结果总是得到null。
<soap:Body>
<Quote>
<ROLE>Error</ROLE>
<ERRORCODE>3</ERRORCODE>
<ERRORSTRING>Username and password wrong!!!</ERRORSTRING>
</Quote>
</soap:Body>
</soap:Envelope>
我正在尝试读取每个节点值XMLPullParser
XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myparser = xmlFactoryObject.newPullParser();
myparser.setInput(inputStream, null);
int event = myparser.getEventType();
while (event != XmlPullParser.END_DOCUMENT)
{
String name=myparser.getName();
switch (event){
case XmlPullParser.START_TAG:
if(name.equals("ERRORSTRING")){
Log.e("Tag ","if xml data "+myparser.getAttributeValue(name,"value"));
}
break;
case XmlPullParser.END_TAG:
if(name.equals("Quote")){
Log.e("Tag ","xml data "+myparser.getAttributeValue(null,"ERRORSTRING"));
}
break;
}
event = myparser.next();
}
结果为空值。
任何人都可以帮助我。
答案 0 :(得分:0)
这样做:
XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myparser = xmlFactoryObject.newPullParser();
myparser.setInput(inputStream, null);
int event = myparser.getEventType();
while (event != XmlPullParser.END_DOCUMENT)
{
String name=myparser.getName();
switch (event){
case XmlPullParser.START_TAG:
if(name.equals("ERRORSTRING")){
Log.e("Tag ","if xml data "+myparser.getAttributeValue(name,"value"));
if(name.equals("Quote")){
Log.e("Tag ","xml data "+myparser.getAttributeValue(null,"ERRORSTRING"));
}
break;
case XmlPullParser.END_TAG:
break;
}
event = myparser.next();
}