安卓:用解析XML KSOAP [英] Android: Parsing XML with KSOAP
问题描述
我做我的web服务(SOAP)这是我从我怎么能分析这个结果没有SAX解析器的web服务收到的XML结果连接...
< maintag>
<项目>
<名称>&AndroidPeople LT; /名称>
<网站类=机器人> www.androidpeople.com< /网站>
< /项目>
<项目>
<名称>&iPhoneAppDeveloper LT; /名称>
<网站类=iPhone> www.iphone-app-developer.com< /网站>
< /项目>
< / maintag>
编辑:/我想知道用Kxmlparser来解析这个结果,有谁能够告诉我怎么样?
非常感谢!
SOAP文件
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.main);
电视=(的TextView)findViewById(R.id.TextView01); // Maak EEN的Nieuw SOAP请求对象的连接参数
SoapObject要求=新SoapObject空间(namespace,METHOD_NAME); request.addProperty(GUID,4fe78-a4s4df8-65a4sd-465as4a);
request.addProperty(InstallVersion,1); //的SoapEnvelope versie面包车web服务
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE; envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(请求); //交通运输gegevens vanaf网址
HttpTransportSE AHT =新HttpTransportSE(URL); 尝试
{
aht.call(SOAP_ACTION,信封);
SoapPrimitive resultsString =(SoapPrimitive)envelope.getResponse();
tv.setText(结果:+ resultsString);
} 赶上(例外五)
{
e.printStackTrace();
}
}
}
根据您的web服务,你得到的将是无论是SoapPrimitive或SoapObject的响应。最喜欢它是一个更复杂的反应,因此,您的code
SoapPrimitive resultsString =(SoapPrimitive)envelope.getResponse();
应该像这样被换成
SoapObject响应=(SoapObject)envelope.getResponse();
这又与有从响应的值的属性和属性。这可能是最简单的只是设置一个断点,并有现场检验。
您也可以看看关于如何调试和看到原始的XML请求和响应在这里我的wiki文档:
HTTP://$c$c.google.com/p/ksoap2 -Android /维基/ CodingTipsAndTricks
I make connection with my webservices (SOAP) this the xml result that I recieved from the webservices how can I parse this result without SAX parser...
<maintag>
<item>
<name>AndroidPeople</name>
<website category="android">www.androidpeople.com</website>
</item>
<item>
<name>iPhoneAppDeveloper</name>
<website category="iPhone">www.iphone-app-developer.com</website>
</item>
</maintag>
EDIT:/ I was wondering to parse this result with Kxmlparser, can anybody tell me how?
Many thanks!
SOAP FILE
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.TextView01);
// Maak een nieuw Soap Request object en parameter
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("GUID","4fe78-a4s4df8-65a4sd-465as4a");
request.addProperty("InstallVersion","1");
// Soapenvelope versie van webservice
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);
// Transport gegevens vanaf URL
HttpTransportSE aht = new HttpTransportSE(URL);
try
{
aht.call(SOAP_ACTION, envelope);
SoapPrimitive resultsString = (SoapPrimitive)envelope.getResponse();
tv.setText("Result :" + resultsString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Depending on your webservice the response you get will be either a SoapPrimitive or a SoapObject. Most like it is a more complex response and therefore your code
SoapPrimitive resultsString = (SoapPrimitive)envelope.getResponse();
should be replaced with something like this
SoapObject response = (SoapObject)envelope.getResponse();
which in turn with have attributes and properties with the values from your response. It might be easiest to just set a breakpoint there and inspect it live.
You can also look at my wiki documentation on how to debug and see the raw xml request and response here: http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks
这篇关于安卓:用解析XML KSOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!