У меня есть XML, который обрабатывается с помощью JAXB. Я не понимаю, почему я не могу получить доступ к внутреннему элементу этого тега.Внутренний элемент JAXB игнорируется
XML фрагмент:
<binary>
<route>
<payload source="SomeService" version="1.2"><![CDATA[ACAA8f///...snip...AAAAAGGAAAARAFR]]>
</payload>
</route>
</binary>
Из этого я сгенерировал XSD:
<xsd:element name="binary">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="route">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="payload">
<xsd:complexType>
<xsd:attribute name="source" type="xsd:string" />
<xsd:attribute name="version" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Я использую Maven-jaxb2-плагин и все работает хорошо:
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
На мой объект, у меня есть методы для getSource() и getVersion(), но нет getValue() или что-то в этом роде. Я вообще чего-то не хватает? Не пытаетесь ли вы получить доступ к данным внутреннего элемента таким образом?
EDIT: включен генерируется Java-код
/**
* <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">
* <attribute name="source" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public static class Payload {
@XmlAttribute(name = "source")
protected String source;
@XmlAttribute(name = "version")
protected String version;
@XmlValue
protected String value;
/**
* Gets the value of the source property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getSource() {
return source;
}
/**
* Sets the value of the source property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setSource(String value) {
this.source = value;
}
/**
* Gets the value of the version property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getVersion() {
return version;
}
/**
* Sets the value of the version property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setVersion(String value) {
this.version = value;
}
}
Добавьте код Java, который вы создали, и то, что вопрос, который вы столкнулись с кодом. – Chaitanya
Проблема заключается в том, что объект Solution.Binary.Route.Payload содержит методы для атрибутов, но не данные внутреннего элемента (я ожидал бы, что метод будет извлекать строковые данные CDATA). – Pythonicus