我有一个不是自己创建而是从另一方收到的 XSD。所以我不能改变这个XSD,因为我必须确保与对方的兼容性。
使用简单绑定模式的 XJC 2.2 和 JAXB 2.2 我想在一个空的 hello 元素中创建一个根元素。但是当编组时,我得到了很多额外的命名空间废话。在我看来,这似乎是不必要的。(它虽然有效,但要发送更多数据等......)
XSD 根元素:
<element name="epp">
<complexType>
<choice>
<element name="greeting" type="epp:greetingType" />
<element name="hello" />
<element name="command" type="epp:commandType" />
<element name="response" type="epp:responseType" />
<element name="extension" type="epp:extAnyType" />
</choice>
</complexType>
</element>
Java代码:
Epp epp = new Epp();
epp.setHello("");
编组结果:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></hello>
</epp>
首选结果:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello />
</epp>
或者:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello></hello>
</epp>
有没有办法让这成为可能,最好不更改 XSD 或手动更改 XJC 编译的类?