考慮以下綁定(片段):JAXB 2個綁定工作不正常
<jaxb:bindings node="//xsd:element[@name='CONDITION']/xsd:complexType/xsd:sequence/xsd:element[@name='OPERAND'][position()=1]">
<jaxb:property name="firstOperand"/>
</jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='CONDITION']/xsd:complexType/xsd:sequence/xsd:element[@name='OPERAND'][position()=2]">
<jaxb:property name="secondOperand"/>
</jaxb:bindings>
而下面的XML模式(片段):
<xsd:element name="CONDITION">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OPERAND" type="OPERANDType"/>
<xsd:element name="OPERATOR" type="xsd:string" />
<xsd:element name="OPERAND" type="OPERANDType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="OPERANDType">
<xsd:choice>
<xsd:element name="SPECIALCONSTANT" type="xsd:string" />
<xsd:element name="CONSTANT" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
而下面的輸入:
<OPERAND>
<CONSTANT>Test1</CONSTANT>
</OPERAND><OPERATOR>myOperator</OPERATOR>
<OPERAND>
<CONSTANT>Test2</CONSTANT>
</OPERAND>
有人可以解釋爲什麼「getSecondOperand」返回null,爲什麼「getFirstOperand」實際上是con保持「Test2」的CONSTANT值?
使用:
- JAXB 2.2.4u1
- 的Java 1.6.0_23
- 阿帕奇Maven的3.0.1
- Maven的JAXB2插件版本0.8.0
編輯:JAXB生成( Java文檔的存取/存取器取出。
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="OPERAND" type="{}OPERANDType"/>
* <element name="OPERATOR" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="OPERAND" type="{}OPERANDType"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"firstOperand",
"operator",
"secondOperand"
})
@XmlRootElement(name = "CONDITION")
public class CONDITION {
@XmlElement(name = "OPERAND", required = true)
protected OPERANDType firstOperand;
@XmlElement(name = "OPERATOR", required = true)
protected String operator;
@XmlElement(name = "OPERAND", required = true)
protected OPERANDType secondOperand;
public OPERANDType getFirstOperand() {
return firstOperand;
}
public void setFirstOperand(OPERANDType value) {
this.firstOperand = value;
}
public String getOPERATOR() {
return operator;
}
public void setOPERATOR(String value) {
this.operator = value;
}
public OPERANDType getSecondOperand() {
return secondOperand;
}
public void setSecondOperand(OPERANDType value) {
this.secondOperand = value;
}
}
看到綁定並沒有幫助。我們需要看到生成的代碼。 – skaffman 2012-01-29 23:34:18
@skaffman:添加了生成的代碼。讓我知道如果還有什麼可以幫助。 – AndrewBourgeois 2012-01-30 07:51:08