我尝试过程中使用出货的Java 7的JAXB实现我使用这些版本的一些XML文件:JAXB处理
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架构的问题decalaration如下:
<xsd:complexType name="CategorizeType">
<xsd:complexContent>
<xsd:extension base="se:FunctionType">
<xsd:sequence>
<xsd:element ref="se:LookupValue"/>
<xsd:element ref="se:Value"/>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="se:Threshold"/>
<xsd:element ref="se:Value"/>
</xsd:sequence>
<xsd:element ref="se:Extension" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="thresholdBelongsTo"
type="se:ThresholdBelongsToType" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
正如你所看到的,se有两个显式的出现:Type中的Value。但是,它不会停止使用xjc编译。如果我有这种类型生成的Java类一看,我可以看到,它是theoritically可以使用以下方法来检索的
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="se:Threshold"/>
<xsd:element ref="se:Value"/>
</xsd:sequence>
元素:
public List<Object> getThresholdAndValue() {
if (thresholdAndValue == null) {
thresholdAndValue = new ArrayList<Object>();
}
return this.thresholdAndValue;
}
不幸的是,如果我试图让列表的元素,我只能取回我的XML文件,其中CategorizeType实例定义如下注册门槛的元素:
<Categorize thresholdsBelongTo="succeeding" fallbackValue="0">
<LookupValue>
<ns3:ValueReference>OUI_EEE92</ns3:ValueReference>
</LookupValue>
<Value>0.3</Value>
<Threshold>30.0</Threshold>
<Value>0.4</Value>
<Threshold>40.0</Threshold>
<Value>0.45</Value>
<Threshold>45.0</Threshold>
<Value>0.5</Value>
<Threshold>50.0</Threshold>
<Value>0.55</Value>
<Threshold>55.0</Threshold>
<Value>0.6</Value>
<Threshold>60.0</Threshold>
<Value>0.7</Value>
<Threshold>70.0</Threshold>
<Value>0.8</Value>
<Extension>
<ExtensionParameter name="method">MANUAL</ExtensionParameter>
</Extension>
</Categorize>
瓦在检索列表中,我只能看到阈值。
我做错了什么?它是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的工作
EDIT2:
我只是尝试自订binginds,在意见提出。我绑定文件如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jxb:bindings jxb:version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<jxb:bindings schemaLocation="schema.xsd"
node="//xsd:complexType[@name='CategorizeType']">
<jxb:bindings
node="xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@ref='se:Value'][position()=1]">
<jxb:property name="FirstValue"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
的第一个值实例是由firstValue属性在Java代码中的确更换
@XmlElement(name = "Value", required = true)
protected ParameterValueType firstValue;
@XmlElements({
@XmlElement(name = "Threshold", type = LiteralType.class),
@XmlElement(name = "Value", type = ParameterValueType.class)
})
protected List<Object> thresholdAndValue;
public ParameterValueType getFirstValue() {
return firstValue;
}
public void setFirstValue(ParameterValueType value) {
this.firstValue = value;
}
public List<Object> getThresholdAndValue() {
if (thresholdAndValue == null) {
thresholdAndValue = new ArrayList<Object>();
}
return this.thresholdAndValue;
}
不幸的是,我仍然能获得同样的结果 - 我仍然不能在由getThresholdAndValues()返回的列表中查看我的值。我还在探索定制的方式...
getThresholdAndValue方法的注释是什么?这是有趣的部分,而不是方法体。 – skaffman
无。我可以在课堂上找到唯一的注释,并在课堂上和属性上进行设置。他们都没有设置方法... – Agemen
有趣的问题 - 请你可以发布完整的模式? – davidfrancis