2
我有一個基於Java Spring的Web服務,它返回了一些響應。我想設計響應,以便它具有通用性,因爲有很多字段總是可用的,並且調用服務的結果放置在JAXB響應中的「有效內容」元素中。要做到這一點,我想出了以下響應類型定義:如何在現有類型中聲明或定義泛型xsd類型。
<xs:element name="serviceResponse">
<xs:element name="responseStatus" type="xs:int"/>
<xs:element name="errorNumber" type="xs:int"/>
<xs:element name="errorDescription" type="xs:string"/>
<xs:element name="payLoad" type="?????"/>
</xs:element>
我怎樣才能申報有效載荷元素如果元素的類型可以根據服務類型是不同的。每個服務都會生成一個我想添加到「PayloadElement」中的不同的JAXB類型。例如,下面是幾個例子迴應,我會想到:
客戶名單:
<serviceResponse>
<responseStatus>0</responsesStatus>
<errorNumber>0</errorNumber>
<errorDescription>null</errorDescription>
<payLoad>
<customers>
<customer>
<customerId>2323</customer>
<customerName>Joe Bloggs</customerName>
<invoiceNumber>90347347</invoiceNumber>
</customer>
<customer>
<customerId>54</customer>
<customerName>Dave hewitt</customerName>
<invoiceNumber>342343</invoiceNumber>
</customer>
</customers>
</payLoad>
</serviceResponse>
訂單
<serviceResponse>
<responseStatus>0</responsesStatus>
<errorNumber>0</errorNumber>
<errorDescription>null</errorDescription>
<payLoad>
<orders>
<order>
<orderId>567</orderId>
<ProductList>
<product>
<productId>234324</product>
<Quantity>5</Quantity>
</product>
<product>
<productId>23434</product>
<Quantity>7</Quantity>
</product>
</ProductList>
</order>
<order>
<orderId>34232</orderId>
<ProductList>
<product>
<productId>1231</product>
<Quantity>5</Quantity>
</product>
</ProductList>
</order>
</orders>
</payLoad>
</serviceResponse>
的列表,你可以看到有效載荷元素可以包括XML文檔可以是多種類型之一。我如何在serviceResponse元素定義中聲明這個?
謝謝
以下應該有所幫助:http://blog.bdoughan.com/2010/08/using-xmlanyelement-to-build-generic.html – 2012-08-05 12:57:34