解析用的DiffGram复杂的SOAP响应 [英] Parsing Complex Soap Response with diffgram
问题描述
我不能够解析低于从.NET Web服务,我获得两个类型的反应之一是,我已经解析它anytype类型的格式,但现在我需要解析如下XML
SOAP响应 <肥皂:信封的xmlns:SOAP =http://schemas.xmlsoap.org/soap/envelope/的xmlns:XSI =HTTP://www.w3。组织/ 2001 / XML模式实例的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
<肥皂:身体与GT;
< GetReminderResponse的xmlns =http://tempuri.org/>
< GetReminderResult>
< XS:模式ID =NewDataSet的xmlns =的xmlns:XS =http://www.w3.org/2001/XMLSchema中的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATA >
< XS:元素的名称=NewDataSetMSDATA:IsDataSet =真MSDATA:UseCurrentLocale =真正的>
< XS:复杂类型>
< XS:选择的minOccurs =0的maxOccurs =无界>
< XS:元素的名称=表>
< XS:复杂类型>
< XS:序列>
< XS:元素的名称=RemMessage类型=XS:字符串的minOccurs =0/>
< XS:元素的名称=InvM_Id类型=XS:INT的minOccurs =0/>
< XS:元素的名称=的DocType类型=XS:INT的minOccurs =0/>
< XS:元素的名称=PrmR_TypeId类型=XS:INT的minOccurs =0/>
< XS:元素的名称=PrmR_Id类型=XS:INT的minOccurs =0/>
< / XS:序列>
< / XS:复杂类型>
< / XS:组件>
< / XS:选择>
< / XS:复杂类型>
< / XS:组件>
< / XS:架构>
< diffgr:的DiffGram的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATA的xmlns:diffgr =瓮:架构 - 微软COM:XML-的DiffGram-V1>
< NewDataSet的xmlns =>
<表diffgr:ID =表1MSDATA:rowOrder =0>
< RemMessage> Exeed贴现额度的发票上的日期为2015年4月5日为Andrea迪诺罗尼亚,从3 - Lokhandwala陈列室和LT; / RemMessage>
< InvM_Id> 78455< / InvM_Id>
&所述;!DOCTYPE→3&下; /的DocType>
&所述; PrmR_TypeId→3&下; / PrmR_TypeId>
< PrmR_Id> 2213< / PrmR_Id>
< /表>
&所述;表diffgr:ID =表2MSDATA:rowOrder =1>
< RemMessage> Exeed贴现额度的发票上的日期为2015年4月5日为ADITI SHAH,从3 - Lokhandwala陈列室和LT; / RemMessage>
< InvM_Id> 78456< / InvM_Id>
&所述;!DOCTYPE→3&下; /的DocType>
&所述; PrmR_TypeId→3&下; / PrmR_TypeId>
< PrmR_Id> 2214< / PrmR_Id>
< /表>
< / NewDataSet>
< / diffgr:&的DiffGram GT;
< / GetReminderResult>
< / GetReminderResponse>
< / SOAP:身体与GT;
< / SOAP:信封>
有在你的肥皂响应wchich数据类型的架构是完全地我怪异。但我一直内置code忽略的xs:架构的一部分,并创建GetReminder对象的数组(从您的previous后采取类型:<一href=\"http://stackoverflow.com/questions/29297741/how-to-parse-diffgram-anytype-response-from-net-webservice\">How解析从.NET Web服务的DiffGram anytype来响应)。我认为,更好的办法将为该结构创建KVMSerializables但低于它的工作方式太伟大;)
的ArrayList&LT; GetReminder&GT; LST =新的ArrayList&LT; GetReminder&GT;();
如果(envelope.bodyIn的instanceof SoapObject&放大器;&安培;!envelope.bodyIn = NULL){
SoapObject所以=(SoapObject)envelope.bodyIn;
如果(so.hasProperty(GetReminderResult)){
SoapObject SO1 =(SoapObject)so.getProperty(GetReminderResult);
如果(so1.hasProperty(的DiffGram)){
SoapObject soDiffg =(SoapObject)so1.getProperty(的DiffGram);
如果(soDiffg.hasProperty(NewDataSet)){
SoapObject soNDSet =(SoapObject)soDiffg.getProperty(NewDataSet); 的for(int i = 0; I&LT; soNDSet.getPropertyCount();我++){
SoapObject SOREM =(SoapObject)soNDSet.getProperty(ⅰ);
GetReminder提醒=新GetReminder(); 如果(soRem.hasProperty(RemMessage)){
reminder.setRemMessage(soRem.getPropertyAsString(RemMessage));
}
如果(soRem.hasProperty(InvM_Id)){
reminder.setInvM_Id(Integer.valueOf(soRem.getPropertyAsString(InvM_Id)));
}
如果(soRem.hasProperty(的DocType)){
reminder.setDocType(Integer.valueOf(soRem.getPropertyAsString(的DocType)));
}
如果(soRem.hasProperty(PrmR_TypeId)){
reminder.setPrmR_TypeId(Integer.valueOf(soRem.getPropertyAsString(PrmR_TypeId)));
}
如果(soRem.hasProperty(PrmR_Id)){
reminder.setPrmR_Id(Integer.valueOf(soRem.getPropertyAsString(PrmR_Id)));
} lst.add(提示);
}
}
}
}
} 的System.out.println(lst.size());
问候,马尔辛 -
I am not able to parse below soap response from a .net webservice,i am getting two type of response one is of anytype format which i have parsed it,but now i need to parse the below 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>
there is schema of data types in Your Soap-response wchich is completly weird for me. But i've built code that ignores xs:schema part and creates array of GetReminder objects (type taken from Your previous post: How to parse diffgram anytype response from .net webservice). I think, that better idea would be creating KVMSerializables for the structure but the way below it works great too ;)
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());
Regards, Marcin
这篇关于解析用的DiffGram复杂的SOAP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!