我有complexType
的XSD架构,其中包含choice
元素。
<xsd:complexType mixed="true" name="CreateApprovedPurchaseRequestType">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element maxOccurs="unbounded" minOccurs="0" name="ALSRules" type="RuleSetType"/>
<xsd:element name="CDFs">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="CDF" type="CDFType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="RequestId" type="xsd:string" use="optional"/>
</xsd:complexType>
我想使用XSD
从JAXB
架构maven-jaxb2-plugin
类生成。当我运行maven命令clean install
时,它生成complexType
而没有错误。但choice
元素不包含在类的属性中(也没有getter&amp; setters)。只有@XmlElementRef
注释。
这是生成的类。
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for CreateApprovedPurchaseRequestType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="CreateApprovedPurchaseRequestType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <choice maxOccurs="unbounded" minOccurs="0">
* <element name="ALSRules" type="{}RuleSetType" maxOccurs="unbounded" minOccurs="0"/>
* <element name="CDFs">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="CDF" type="{}CDFType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </choice>
* <attribute name="RequestId" type="{http://www.w3.org/2001/XMLSchema}string" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CreateApprovedPurchaseRequestType", propOrder = {
"content"
})
public class CreateApprovedPurchaseRequestType {
@XmlElementRefs({
@XmlElementRef(name = "ALSRules", type = JAXBElement.class, required = false),
@XmlElementRef(name = "CDFs", type = JAXBElement.class, required = false)
})
@XmlMixed
protected List<Serializable> content;
@XmlAttribute(name = "RequestId")
protected String requestId;
/**
* Gets the value of the content property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the content property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link CreateApprovedPurchaseRequestType.CDFs }{@code >}
* {@link String }
* {@link JAXBElement }{@code <}{@link RuleSetType }{@code >}
*
*
*/
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
/**
* Gets the value of the requestId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getRequestId() {
return requestId;
}
/**
* Sets the value of the requestId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setRequestId(String value) {
this.requestId = value;
}
/**
* <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="CDF" type="{}CDFType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"cdf"
})
public static class CDFs {
@XmlElement(name = "CDF")
protected List<CDFType> cdf;
/**
* Gets the value of the cdf property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the cdf property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getCDF().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link CDFType }
*
*
*/
public List<CDFType> getCDF() {
if (cdf == null) {
cdf = new ArrayList<CDFType>();
}
return this.cdf;
}
}
}
我尝试使用绑定文件和设置权限生成。但它没有任何影响,我无法达到预期的效果。
<jxb:bindings
xmlns="http://www.w3.org/1999/xhtml"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jxb:globalBindings choiceContentProperty="true">
<xjc:simple />
</jxb:globalBindings>
</jxb:bindings>