我正在尝试使用 Castor 将 POJO 映射到 XML。
假设我有一个包含项目集合的订单...是否有任何方法可以实现如下所示的 xml:
<order>
...order attributes
<items>
<item> ..item attributes </item>
<item> ..other item </item>
</items>
</order>
我可以做类似的东西,但没有 <items>
节点。在其他情况下这不会成为问题,但我的 XML 必须遵守严格的 XSD 架构,因此我需要这样做。
谢谢!
<小时/>我想到了一种“解决方法”,其中涉及创建一个新的 java 对象(即节点),该对象仅包含项目列表......有人能想到更好的方法吗?从现在开始有 100 名代表的赏金开放!
最佳答案
您可以使用bind-xml元素的location属性
http://castor.codehaus.org/1.2/xml-mapping.html#6.-Location-attribute
文档中的示例:
<class name="Foo">
<field name="bar" type="Bar">
<bind-xml name="bar" location="abc"/>
</field>
</class>
生成以下 XML:
<foo>;
<abc>
<bar>...</bar>
</abc>
</foo>
关于java - 在 Castor 中将集合映射到 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1314835/