0

次のような XML 文字列があります。

<Tree Name="tree1">
    <Service>Service1</Service>
    <Tree Name="tree2">
         <Service>Service2</Service>
         <Service>Service3</Service>
    </Tree>
    <Service>Service4</Service>
    <Tree Name="tree3">
        <Service>Service4</Service>
        <Service>service5</Service>
    </Tree>
</Tree>

およびバインディング構造:

    <mapping ordered="false" allow-repeats="true" abstract="true" type-name="Tree"
         class="Tree">
    <collection ordered="false" allow-repeats="true" get-method="getTrees" set-method="setTrees" usage="optional">
        <structure usage="optional" ordered="false" allow-repeats="true" map-as="Tree" name="Tree"/>
    </collection>
    <collection ordered="false" allow-repeats="true"  get-method="getServices" set-method="setServices" usage="optional">
        <structure usage="optional" ordered="false" allow-repeats="true"   map-as="Service" name="Service"/>
    </collection>
    <value style="attribute" name="Name" get-method="getName" set-method="setName" usage="optional"/>
    </mapping>

しかし、xml を unmarshall しようとすると、ルートで 1 つのツリーと 1 つのサービスのみをキャッチします。xml からすべてのデータを取得する可能性はありますか?

4

1 に答える 1

0

私はbinding.xmlでそのような構造を使用することによってこの問題を解決しました:

<collection ordered="false" get-method="getCollection" set-method="setCollection" usage="optional">
      <structure map-as="Service" name="Service" usage="optional"/>
      <structure map-as="Tree" name="Tree" usage="optional"/>
</collection>

これにより、すべての要素を含むコレクションが得られ、手動で並べ替えることができます。

于 2012-06-19T13:56:41.827 に答える