【发布时间】:2014-10-03 21:11:15
【问题描述】:
当列表中的某个子项引用此列表中的其他子项时,我如何使用 XStream 从 XML 获取对象。 尝试:
<projectEstimate id="586">
<projectEstimateKosgus class="list">
<projectEstimateKosgu>
<amount>1.00</amount>
<parent class="projectEstimateKosgu" reference="/projectEstimate/projectEstimateKosgus/projectEstimateKosgu[2]"/>
<estimate class="projectEstimate" reference="/projectEstimate"/>
</projectEstimateKosgu>
<projectEstimateKosgu>
<amount>2.00</amount>
<estimate class="projectEstimate" reference="/projectEstimate"/>
</projectEstimateKosgu>
</projectEstimateKosgus>
</projectEstimate>
projectEstimate 对象具有集合字段“projectEstimateKosgus”,并且该集合的子对象具有字段“parent”,该字段引用了该集合中的“projectEstimateKosgu”对象。当我尝试在标签中设置父级时,它位于引用标签的上方,我得到:
com.thoughtworks.xstream.converters.ConversionException: Invalid reference
但这有效,如果改变“projectEstimateKosgu”标签的顺序,像这样
<projectEstimate id="586">
<projectEstimateKosgus class="list">
<projectEstimateKosgu>
<amount>2.00</amount>
<estimate class="projectEstimate" reference="/projectEstimate"/>
</projectEstimateKosgu>
<projectEstimateKosgu>
<amount>1.00</amount>
<parent class="projectEstimateKosgu" reference="/projectEstimate/projectEstimateKosgus/projectEstimateKosgu"/>
<estimate class="projectEstimate" reference="/projectEstimate"/>
</projectEstimateKosgu>
</projectEstimateKosgus>
</projectEstimate>
【问题讨论】:
-
欢迎来到 SO,我认为这个 Object References 链接可能会对您有所帮助。