我有一个JAXB设置,我使用@XmlJavaTypeAdapter将类型为Person
的对象替换为仅包含此人的UUID的PersonRef
类型的对象。这工作非常好。但是,生成的XML在每次使用时都重新声明相同的名称空间(xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
)。虽然这通常是好的,但它感觉不对。JAXB:如何避免xmlns的重复名称空间定义:xsi
如何配置JAXB在文档的最开始处声明xmlns:xsi?我可以手动将名称空间声明添加到根元素吗?
这里是什么,我想才达到一个例子:
电流:
<person uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a">
<relation type="CHILD">
<to xsi:type="personRef" uuid="56a930c0-5499-467f-8263-c2a9f9ecc5a0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</relation>
<relation type="CHILD">
<to xsi:type="personRef" uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</relation>
<!-- SNIP: some more relations -->
</person>
通缉:
<person uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<relation type="CHILD">
<to xsi:type="personRef" uuid="56a930c0-5499-467f-8263-c2a9f9ecc5a0"/>
</relation>
<relation type="CHILD">
<to xsi:type="personRef" uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a"/>
</relation>
<!-- SNIP: some more relations -->
</person>
我使用jaxb2,这对我并不适用,抛出RuntimeException – arrehman 2012-03-02 19:51:44