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 时,我在根目录中只捕获了一棵树和一个服务。是否有任何可能从 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 回答