1
我有一些使用JAXB處理的XML。我不明白爲什麼我不能訪問這個標籤的內部元素。忽略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()或沿着這些線的東西。我從根本上失去了一些東西?試圖以這種方式訪問內部元素數據不正確?
編輯:包括生成的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