我有一個預定義的xsd模式(我不能修改),我喜歡通過JAXB生成相應的JAVA類。目前我正在努力處理一個複雜的類型,定義如下。JAXB從任何類型訪問字符串內容
<xsd:complexType name="AttributeType">
<xsd:complexContent>
<xsd:extension base="xsd:anyType">
<xsd:attribute name="id" type="xsd:anyURI" use="required"/>
<xsd:anyAttribute processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
提供的XML實例中,允許直接串的內容,這樣的:
<attribute id="myValue">201</attribute>
以及嵌入XML這樣的:
<attribute id="address">
<example:Address xmlns:example="http://example.com/ns">
<Street>100 Nowhere Street</Street>
<City>Fancy</City>
<State>DC</State>
<Zip>99999</Zip>
</example:Address>
</attribute>
當運行XJC過程無需進一步結合修改,我得到這樣一個類:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AttributeType", propOrder = {
"any"
})
public class AttributeType {
@XmlAnyElement
protected List<Element> any;
@XmlAttribute(name = "id", required = true)
@XmlSchemaType(name = "anyURI")
protected String id;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
// getter setter omitted
}
問題在於,我無法獲取第一個示例的字符串內容。這可能會引用XSD anytype and JAXB,但實際上我不知道如何在不修改XSD的情況下實現此目的。因此,我如何獲得字符串內容?順便說一句。我使用maven cxf-codegen插件來生成源代碼。
你能解決問題嗎?引用的鏈接[鏈接](https://stackoverflow.com/questions/3488141/xsd-anytype-and-jaxb)是完全相同的問題,我試圖找出如何克服它。那裏的答案沒有解決。 – JGlass