【问题标题】:Soap response Parsing肥皂响应解析
【发布时间】:2012-06-27 09:44:32
【问题描述】:

我已经复制了我在浏览器上得到的 Soap 响应,我如何在 Android 中使用 soap 解析这个响应? 我用过 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>

【问题讨论】:

  • 您可以使用 SAX/DOM 解析器来解析响应。有很多相同的教程。
  • 您应该编辑问题以修复代码显示。我尝试了两次,但由于某种原因,我的编辑一直被拒绝?
  • 我刚刚复制了浏览器上的整个 xml 响应。我不知道为什么它在这里看起来不合适。

标签: android soap xml-parsing


【解决方案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());

}

【讨论】:

【解决方案2】:

我认为你是编程新手。你不能解析这个xml文件,因为这是webservice的服务描述。webservice会有方法,在你的浏览器中点击这些方法,你会得到任何客户端都可以调用的xml输出数据并解析。另请参阅此web service in android/eclipse 以解析您的数据。

【讨论】:

  • 大家好,我在不使用 xml 解析器的情况下成功解析了复杂的 SOAP 响应......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
  • 2011-12-29
相关资源
最近更新 更多