0

我有以下 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>

我写了以下投标,但由于命名空间“tra”而无法正常工作

<?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>

有什么想法可以让我完成这项工作吗?

4

1 回答 1

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=”添加到使用该命名空间的任何元素(除非“默认=”子句适用)。在这种情况下,您不想为“trade”元素使用默认命名空间。您想使用其他命名空间。

只有当您计划将此绑定用于输出时,才需要前缀=。

于 2013-08-16T20:50:06.037 回答