XML parsing using kasoap2-Android

一个人想着一个人 提交于 2019-12-07 17:18:31

问题


i have difficulties parsing this structure xml:

<Publications>
<Publication>
<PublicationID>1</PublicationID>
<PublisherID>1</PublisherID>
<Date>2012-03-28 13:39:04</Date>
</Publication>
<Publication>
<PublicationID>2</PublicationID>
<PublisherID>1</PublisherID>
<Date>2012-01-23 10:00:03</Date>
</Publication>
</Publications> 

Maybe some one could give me some ides how to parse it ?

My request looks:

String method_name = "GetPublications";

// creating new SoapObject
soap = GetSoapObject(method_name);

SoapSerializationEnvelope envelope = GetEnvelope(soap);

HttpTransportSE androidHttpTransport = new HttpTransportSE(REQUEST_URL);

androidHttpTransport.call(NAMESPACE + method_name, envelope);

soap = (SoapObject) envelope.getResponse();

kSoap2-Android is returning:

anyType{Publications=anyType{Publication=anyType{PublicationID=1; PublisherID=1; Date=2012-03-28 13:39:04; }; Publication=anyType{PublicationID=2; PublisherID=1; Date=2012-01-23 10:00:03; }; }; }

Thanks.


回答1:


Parsing the xml file like:

Step1: Creating class java bean like:

public class Publication { 
Integer PublicationId;
Integer PublisherID;
Date    date; 

//define methods get, set for fields
}

Step2: using KSOAP2 to implement what you think by Using :

soap = (SoapObject) envelope.bodyIn
soapResult = (SoapObject)soap.getProperty(0);
for(int i=0;i<soapResult.getPropertyCount();i++)
{
   SoapObject so = (SoapObject) soapResult.getProperty(i);
 //here, you can get data from xml using so.getProperty("PublicationID") 
 //or the other tag in xml file.
}

Hope it will be useful for you.



来源:https://stackoverflow.com/questions/10087480/xml-parsing-using-kasoap2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!