2012-06-27 40 views
-2

我已經複製了我在瀏覽器上得到的肥皂響應,我如何解析這個響應在Android使用肥皂?我已經使用SoapObject obj =(SoapObject)mySoapEnvelop.getResponse(); 但我得到obj.getPropertyCount()= 1。肥皂響應解析

我很困惑,在這一點上,任何一個可以幫助我出來?

這裏是我的完整響應:

真正

<Data> 
    <xs:schema id="NewDataSet" > 
     <xs:element 
      name="NewDataSet" 
      msdata:IsDataSet="true" 
      msdata:Locale="" > 
      <xs:complexType> 
       <xs:choice 
        maxOccurs="unbounded" 
        minOccurs="0" > 
        <xs:element name="Table" > 
         <xs:complexType> 
          <xs:sequence> 
           <xs:element      
            name="ID" 
            minOccurs="0" 
            type="xs:int" /> 
           <xs:element 
            name="UniqueID" 
            minOccurs="0" 
            type="xs:string" 
            msdata:DataType="System.Guid, mscorlib, 
      Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>   
           <xs:element 
            name="FullName" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="Title" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="Phone" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="Email" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="CreatedDate" 
            minOccurs="0" 
            type="xs:dateTime" /> 
           <xs:element 
            name="Website" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="CompanyName" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="LeadStatus" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="StatusName" 
            minOccurs="0" 
            type="xs:string" /> 
           <xs:element 
            name="IsRead" 
            minOccurs="0" 
            type="xs:boolean" /> 
           <xs:element 
            name="OwnerName" 
            minOccurs="0" 
            type="xs:string" /> 
          </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
       </xs:choice> 
      </xs:complexType> 
     </xs:element> 
    </xs:schema> 

    <diffgr:diffgram> 

     <NewDataSet> 
      <Table 
       diffgr:id="Table1" 
       msdata:rowOrder="0" > 
       <ID>6</ID> 
       <UniqueID>8d93aab5-086f-41bb-b8ec-03b3eb0aa463</UniqueID> 
       <FullName>bhatt</FullName> 
       <Title /> 
       <Phone /> 
       <Email /> 
       <CreatedDate>2012-02-24T13:14:06.773+05:30</CreatedDate> 
       <Website /> 
       <CompanyName>xyz</CompanyName> 
       <LeadStatus>Qualified</LeadStatus> 
       <StatusName>Approved</StatusName> 
       <IsRead>false</IsRead> 
       <OwnerName>Admin admin</OwnerName> 
      </Table> 
     </NewDataSet> 
    </diffgr:diffgram> 
</Data> 

+0

您可以使用SAX/DOM解析器來解析響應。有很多相同的教程。 – AndroGeek

+0

但是我必須使用SOAP – Rohit

+0

您應該編輯問題以修復代碼顯示。我試了兩次,但由於某種原因,我的編輯被拒絕了? –

回答

0

我想你,因爲這是Web服務的服務描述新手programming.You無法分析該XML文件。 Webservice將有方法,在瀏覽器中單擊這些方法,您將獲得任何客戶端可以調用和解析的xml輸出數據。另請參閱此web service in android/eclipse解析您的數據。

+0

嗨,我已經成功地解析複雜的SOAP響應,而不使用XML解析器.... – Rohit

1
SoapObject result = (SoapObject)envelope.bodyIn; 

if(result != null){ 

    int count = result.getPropertyCount(); 
    //TextView t = (TextView)this.findViewById(R.id.resultbox); 
    //t.setText("SOAP response:\n\n" + count); 

    SoapObject nameResult = (SoapObject) result.getProperty(0); 
    // TextView t = (TextView)this.findViewById(R.id.resultbox); 
    //t.setText("SOAP response:\n\n" + nameResult.toString()); 

    SoapObject test = (SoapObject) nameResult.getProperty(1); 
    // TextView t = (TextView)this.findViewById(R.id.resultbox); 
    // t.setText("SOAP response:\n\n" + test.toString()); 

    SoapObject dar = (SoapObject) test.getProperty(0); 
    //TextView t = (TextView)this.findViewById(R.id.resultbox); 
    //t.setText("SOAP response:\n\n" + dar.toString()); 

    SoapObject suvas = (SoapObject) dar.getProperty(0); 
    int c = dar.getPropertyCount(); 
    TextView t = (TextView)this.findViewById(R.id.resultbox); 
    t.setText("SOAP response:\n\n" + suvas.toString()); 
    //t.setText("SOAP response:\n\n" + c); 
    //SoapObject nivas = (SoapObject) suvas.getProperty(NewsId); 
    //TextView t = (TextView)this.findViewById(R.id.resultbox); 
    // t.setText("SOAP response:\n\n" + nivas.toString()); 

} 
+0

你能幫助回答這個問題嗎? http://stackoverflow.com/questions/26903238/how-to-parse-soap-response-when-child-tags-have-different-name-and-no-of-tag-are – 2014-11-13 07:25:37