Jibx与多个名称空间绑定

时间:2013-06-21 09:35:24

标签: java jibx

我需要以下XML来开发

的Jibx绑定
<?xml version="1.0" encoding="UTF-8"?>
<conf:confirmationMessage xmlns:conf="http://webaddress/entity/confirmation/v1_0" xmlns:cli="http://webaddress/entity/client/v1_0" xmlns:cust="http://webaddress/entity/custodian/v1_0" xmlns:fin="http://webaddress/entity/financial/v1_0" xmlns:sto="http://webaddress/entity/stock/v1_0" xmlns:tra="http://webaddress/entity/trade/v1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://webaddress/entity/confirmation/v1_0 ../XSD_V2/Confirmation.xsd ">
   <conf:id>20130313588741</conf:id>
   <conf:status>CS Generated</conf:status>
   <conf:type>INS</conf:type>
   <conf:trade>
       <tra:tradeID>3068353</<tra:tradeID>
       <tra:clientID>82911</<tra:clientID>
       <<tra:tradeDate>2013-02-28T00:00:00</<tra:tradeDate>
   </conf:trade>
</conf:confirmationMessage>

我写了下面的biding但由于命名空间而无法正常工作&#34; tra&#34;

<?xml version="1.0" encoding="UTF-8"?>
<binding>
    <mapping name="confirmationMessage" class="com.webaddress.Confirmation">
        <namespace uri="http://webaddress/entity/confirmation/v1_0" default="elements"/>
        <value name="id" field="id" default="default-value" usage="optional" />
        <value name="status" field="status" default="default-value" usage="optional" />
        <value name="type" field="type" default="default-value" usage="optional" />
        <collection field="trade" factory="com.package.trades.JibxConfirmationUmarshaller.listFactory">
            <!--<structure map-as="com.webaddress.Trade" />-->
            <structure name="trade" />
        </collection>
    </mapping> 

    <mapping name="trade" class=om.webaddress.Trade">
        <namespace prefix="tra" uri="http://webaddress/entity/trade/v1_0" default="elements"/>
        <value name="tradeID" field="tradeID" default="default-value" usage="optional" />

        <value name="clientID" field="clientID" usage="optional"
        deserializer="com.package.trades.JibxConfirmationUmarshaller.deserializeBigInt" />

        <value name="tradeDate" field="tradeDate" usage="optional"
        deserializer="com.package.trades.JibxConfirmationUmarshaller.deserializeDate" />
        <value name="activity" field="activity" default="default-value" usage="optional" />
    </mapping>
</binding>

我是如何做到这一点的?

1 个答案:

答案 0 :(得分:1)

The issue probably lies in the fact that the name "trade" is from the namespace
"http://webaddress/entity/confirmation/v1_0".  Your jibx binding makes it assume
that "trade" is from the namespace "http://webaddress/entity/trade/v1_0".

The strings "conf" and "tra" are just abbreviations for
"http://webaddress/entity/confirmation/v1_0" and "http://webaddress/entity/trade/v1_0"

正确答案可能看起来像这样:

<mapping name="trade" ns="http://webaddress/entity/confirmation/v1_0"class=om.webaddress.Trade">
    <namespace prefix="tra" uri="http://webaddress/entity/trade/v1_0" default="elements"/>
    <namespace uri="http://webaddress/entity/confirmation/v1_0"/>
    <value name="tradeID" field="tradeID" default="default-value" usage="optional" />

    <value name="clientID" field="clientID" usage="optional"
    deserializer="com.package.trades.JibxConfirmationUmarshaller.deserializeBigInt" />

    <value name="tradeDate" field="tradeDate" usage="optional"
    deserializer="com.package.trades.JibxConfirmationUmarshaller.deserializeDate" />
    <value name="activity" field="activity" default="default-value" usage="optional" />
</mapping>

您需要包含您计划使用的任何命名空间的标记,但是您需要将“ns =”添加到使用该命名空间的任何元素(除非应用“default =”子句)。在这种情况下,您不希望使用“trade”元素的默认命名空间。您想使用其他命名空间。

只有在计划将此绑定用于输出时才需要prefix =。