JAXB2的默认
XML输出如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<TEST2 xmlns="http://projects/open/2012/UniformProxySystem">
<XXX1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<XXX2>17:02:26</XXX2>
<XXX3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</TEST2>
但是我想要它如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<TEST2 xmlns="http://projects/open/2012/UniformProxySystem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<XXX1 xsi:nil="true"/>
<XXX2>17:01:08</XXX2>
<XXX3 xsi:nil="true"/>
</TEST2>
寻找帮助,我正在使用JDK6和JAXB 2.1
最佳答案 您可以尝试使用@XmlSchema注释并执行以下操作:
package-info.java
@XmlSchema(
elementFormDefault=XmlNsForm.QUALIFIED,
namespace="http://projects/open/2012/UniformProxySystem",
xmlns={@XmlNs(prefix="xsi",
namespaceURI="http://www.w3.org/2001/XMLSchema-instance")}
)
package com.example;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;