2012-06-11 68 views
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我抓到根只有一棵樹,只有一個服務。是否有任何posibilites從XML獲取所有數據?

回答

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> 

這給了我收集了所有的元素,我可以手動排序。