如何使用模式创建一个改进的soap请求对象?

时间:2017-01-11 07:17:14

标签: java android xml soap retrofit2

我有一个请求 xml ,其中包含架构定义。如何创建需要传递给改进 soap请求的pojo类。

以下是需要创建为pojo的示例 xml 数据

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:Header />
<soap:Body>
    <gbr xmlns="http://tempuri.org/">
        <objhandler>
            <id>
                <int>123</int>
            </id>
            <dp>true</dp>
            <cid>12312</cid>
        </objhandler>
        <dtASNCondensed>
            <xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" id="NewDataSet" xmlns="">
                <xs:element name="NewDataSet" msdata:IsDataSet="true"
                    msdata:MainDataTable="dtASNCondensed" msdata:UseCurrentLocale="true">
                    <xs:complexType>
                        <xs:choice maxOccurs="unbounded" minOccurs="0">
                            <xs:element name="dtASNCondensed">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="id" minOccurs="0" type="xs:string" />
                                        <xs:element name="gid" minOccurs="0" type="xs:string" />
                                        <xs:element name="te" minOccurs="0" type="xs:string" />
                                        <xs:element name="rec" minOccurs="0" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:choice>
                    </xs:complexType>
                </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
                xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
                <DocumentElement xmlns="">
                    <dtASNCondensed diffgr:hasChanges="inserted" diffgr:id="dtASNCondensed1"
                        msdata:rowOrder="0">
                        <id>123</id>
                        <gid>3000037430</gid>
                        <te>102</te>
                        <rec>1</rec>
                    </dtASNCondensed>
                </DocumentElement>
            </diffgr:diffgram>
        </dtASNCondensed>
    </gbr>
</soap:Body>

1 个答案:

答案 0 :(得分:0)

您可以使用简单的xml库来实现,您可以像这样构建您的Retrofit

retrofit =  new Retrofit.Builder()
        .addConverterFactory(SimpleXmlConverterFactory.create(serializer))
        .baseUrl("http://www.webservicex.net/")
        .client(okHttpClient)
        .build();

有关详情,您可以查看此示例https://github.com/asanchezyu/RetrofitSoapSample