jen*_*nil 1 parsing android ksoap2 xml-parsing
我无法解析来自 .net 网络服务的以下soap 响应,我得到两种类型的响应,一种是我解析过的任何类型格式,但现在我需要解析以下 xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetReminderResponse xmlns="http://tempuri.org/">
<GetReminderResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="RemMessage" type="xs:string" minOccurs="0"/>
<xs:element name="InvM_Id" type="xs:int" minOccurs="0"/>
<xs:element name="DocType" type="xs:int" minOccurs="0"/>
<xs:element name="PrmR_TypeId" type="xs:int" minOccurs="0"/>
<xs:element name="PrmR_Id" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<RemMessage>Exeed Discount Limit on Invoice dated on 04/05/2015 for ANDREA NORONHA , from 3 - Lokhandwala Showroom</RemMessage>
<InvM_Id>78455</InvM_Id>
<DocType>3</DocType>
<PrmR_TypeId>3</PrmR_TypeId>
<PrmR_Id>2213</PrmR_Id>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<RemMessage>Exeed Discount Limit on Invoice dated on 04/05/2015 for ADITI SHAH , from 3 - Lokhandwala Showroom</RemMessage>
<InvM_Id>78456</InvM_Id>
<DocType>3</DocType>
<PrmR_TypeId>3</PrmR_TypeId>
<PrmR_Id>2214</PrmR_Id>
</Table>
</NewDataSet>
</diffgr:diffgram>
</GetReminderResult>
</GetReminderResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
你的肥皂响应中有数据类型的模式,这对我来说完全奇怪。但是我已经构建了忽略 xs:schema 部分并创建 GetReminder 对象数组的代码(类型取自您之前的帖子:How to parse diffgram anytype response from .net webservice)。我认为,更好的主意是为结构创建 KVMSerializables,但它下面的方式也很好用 ;)
ArrayList<GetReminder> lst = new ArrayList<GetReminder>();
if(envelope.bodyIn instanceof SoapObject && envelope.bodyIn!=null){
SoapObject so=(SoapObject)envelope.bodyIn;
if(so.hasProperty("GetReminderResult")){
SoapObject so1 = (SoapObject) so.getProperty("GetReminderResult");
if(so1.hasProperty("diffgram")){
SoapObject soDiffg = (SoapObject) so1.getProperty("diffgram");
if(soDiffg.hasProperty("NewDataSet")){
SoapObject soNDSet = (SoapObject) soDiffg.getProperty("NewDataSet");
for (int i = 0; i < soNDSet.getPropertyCount(); i++) {
SoapObject soRem = (SoapObject) soNDSet.getProperty(i);
GetReminder reminder = new GetReminder();
if (soRem.hasProperty("RemMessage")) {
reminder.setRemMessage(soRem.getPropertyAsString("RemMessage"));
}
if (soRem.hasProperty("InvM_Id")) {
reminder.setInvM_Id(Integer.valueOf(soRem.getPropertyAsString("InvM_Id")));
}
if (soRem.hasProperty("DocType")) {
reminder.setDocType(Integer.valueOf(soRem.getPropertyAsString("DocType")));
}
if (soRem.hasProperty("PrmR_TypeId")) {
reminder.setPrmR_TypeId(Integer.valueOf(soRem.getPropertyAsString("PrmR_TypeId")));
}
if (soRem.hasProperty("PrmR_Id")) {
reminder.setPrmR_Id(Integer.valueOf(soRem.getPropertyAsString("PrmR_Id")));
}
lst.add(reminder);
}
}
}
}
}
System.out.println(lst.size());
Run Code Online (Sandbox Code Playgroud)
问候, 马辛
| 归档时间: |
|
| 查看次数: |
1764 次 |
| 最近记录: |