Рассмотрим следующие привязки (фрагмент):
<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» возвращает ноль и почему «getFirstOperand» фактически содержит значение CONSTANT «Test2»?
Использование:- JAXB 2.2.4u1- Java 1.6.0_23- Apache Maven 3.0.1- maven-jaxb2-плагин версия 0.8.0
РЕДАКТИРОВАТЬ: JAXB генерирует (JavaDoc удален для аксессоров / мутаторов:
<code>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>
*
* * * / @XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "", propOrder = {"firstOperand", "operator", "secondOperand"}) @XmlRootElement (name = "CONDITION") открытый класс CONDITION {@XmlElement (name = "OPERAND", обязательно = true) защищенный OPERANDType firstOperand; @XmlElement (name = "ОПЕРАТОР", требуется= true) защищенный оператор String; @XmlElement (name = "OPERAND", обязательный = true) защищенный OPERANDType secondOperand; public OPERANDType getFirstOperand () {return firstOperand;} открытый void setFirstOperand (значение OPERANDType) {this.firstOperand = value;}Строка getOPERATOR () {оператор возврата;} public void setOPERATOR (String value) {this.operator = value;} public OPERANDType getSecondOperand () {return secondOperand;} public void setSecondOperand (OPERANDType value) {this.secondOperand = value;}}