我正在使用
Java 7中提供的JAXB实现来处理一些XML文件.我使用这些版本:
501 ~ % xjc -version
xjc 2.2.4
502 ~ %java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Server VM (build 21.1-b02, mixed mode)
XML模式中的问题解决方案如下:
type="se:ThresholdBelongsToType" use="optional"/>
正如你所看到的,有两种明确的结果:类型中的值.但是,它不会停止使用xjc的编译.而且,如果我看到为这个类生成的Java类,我可以看到这是有可能的,
使用以下方法:
public List getThresholdAndValue() {
if (thresholdAndValue == null) {
thresholdAndValue = new ArrayList();
}
return this.thresholdAndValue;
}
不幸的是,如果我尝试获取列表的元素,我只能检索在我的xml文件中注册为阈值的元素,其中CategorizeType实例定义如下:
OUI_EEE92
0.3
30.0
0.4
40.0
0.45
45.0
0.5
50.0
0.55
55.0
0.6
60.0
0.7
70.0
0.8
MANUAL
检索列表时,我只能看到Threshold值.
我做错了吗是Jaxb的内在限制吗?
请注意,我无法更改XML模式…
编辑:
我刚刚使用-v选项运行xjc,我获得了全局相同的输出.用冗长度:
xjc -verbose se/2.0/All.xsd
parsing a schema...
[WARNING] java.net.SocketException: Unexpected end of file from server
line 23 of file:/home/alexis/crap/SE-Schema-2.0/ows/2.0/ows19115subset.xsd
[WARNING] java.net.SocketException: Unexpected end of file from server
line 22 of file:/home/alexis/crap/SE-Schema-2.0/filter/2.0/filterCapabilities.xsd
compiling a schema...
[INFO] generating codee
unknown location
没有它 :
xjc se/2.0/All.xsd
parsing a schema...
[WARNING] java.net.SocketException: Unexpected end of file from server
line 23 of file:/home/alexis/crap/SE-Schema-2.0/ows/2.0/ows19115subset.xsd
[WARNING] java.net.SocketException: Unexpected end of file from server
line 22 of file:/home/alexis/crap/SE-Schema-2.0/ows/2.0/owsExceptionReport.xsd
compiling a schema...
以下输出只包含生成的文件的名称和位置.
我忘了说这个xsd不能用Java 6附带的xjc进行编译.最后一次尝试使用JAXB 2.1.10.我现在不能再现这个行为,因为我正在使用Java 7 .
编辑2:
我刚刚尝试自定义binginds,如建议在评论.我的绑定文件如下:
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
node="//xsd:complexType[@name='CategorizeType']">
node="xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@ref='se:Value'][position()=1]">
第一个值实例确实被Java代码中的firstValue属性替换
@XmlElement(name = "Value", required = true)
protected ParameterValueType firstValue;
@XmlElements({
@XmlElement(name = "Threshold", type = LiteralType.class),
@XmlElement(name = "Value", type = ParameterValueType.class)
})
protected List thresholdAndValue;
public ParameterValueType getFirstValue() {
return firstValue;
}
public void setFirstValue(ParameterValueType value) {
this.firstValue = value;
}
public List getThresholdAndValue() {
if (thresholdAndValue == null) {
thresholdAndValue = new ArrayList();
}
return this.thresholdAndValue;
}
不幸的是,我仍然得到相同的结果 – 我仍然看不到我的值在getThresholdAndValues()返回的列表中.我还在探索定制方式…