我想使用 jaxb 解组具有此 xsd定义的 XML 文件。
我已经使用 Eclipse 右键单击生成了 java 类,生成了 jaxb 类等。我在解组 XML 文件时没有问题。
问题是我不知道如何取消编组(映射?)元数据类型。下面是 metadataType 的 xsd 定义和生成的类:
<complexType name="metadataType">
<annotation>
<documentation>Metadata must be expressed in XML that complies
with another XML Schema (namespace=#other). Metadata must be
explicitly qualified in the response.</documentation>
</annotation>
<sequence>
<any namespace="##other" processContents="strict"/>
</sequence>
</complexType>
此类型的生成类是:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.11.08 at 05:28:26 PM PST
//
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlType;
/**
* Metadata must be expressed in XML that complies
* with another XML Schema (namespace=#other). Metadata must be
* explicitly qualified in the response.
*
* <p>Java class for metadataType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="metadataType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any namespace='##other'/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "metadataType", propOrder = {
"any"
})
public class MetadataType {
@XmlAnyElement(lax = true)
protected Object any;
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Object }
*
*/
public Object getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object is
* {@link Object }
*
*/
public void setAny(Object value) {
this.any = value;
}
}
外部 xsd 在这里
未编组的 XML 文档生成以下内容:
更新:
另外,我从外部xsd生成了类:
OaiDcType.java ElementType.java
这些类必须包含 MetadataType 对象的数据。
我想将任何转换为我自己的 OaiDcType 对象,这是正确/最佳的方法吗?