我有一个XSD,它不是自己创建的,而是从另一方收到的.所以我不能改变这个XSD,因为我必须确保与另一方的兼容性.
使用简单绑定模式使用XJC 2.2和JAXB 2.2我想在一个空的hello元素内部创建一个根元素.但是当编组时我得到了很多额外的命名空间废话.哪个对我来说看起来不需要.(它虽然有效,但发送的数据更多......)
XSD Rootelement:
<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>
Run Code Online (Sandbox Code Playgroud)
Java代码:
Epp epp = new Epp();
epp.setHello("");
Run Code Online (Sandbox Code Playgroud)
编组结果:
<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>
Run Code Online (Sandbox Code Playgroud)
首选结果:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello />
</epp>
Run Code Online (Sandbox Code Playgroud)
要么:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello></hello>
</epp>
Run Code Online (Sandbox Code Playgroud)
有没有办法使这成为可能,最好不更改XSD或手动更改XJC编译的类?