1

Why would this Schema:

<xsd:complexType name="ErrType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
 <xsd:element name="errorCode" type="xsd:string"/>
 <xsd:element name="errorDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

Generate to this Java code:

class ErrType {
  @XmlElementRefs({
    @XmlElementRef(name = "errorCode", namespace = "http://somewhere/blah.xsd", type = JAXBElement.class),
    @XmlElementRef(name = "errorDescription", namespace = "http://somewhere/blah.xsd", type = JAXBElement.class)
  })
  protected List<JAXBElement<String>> errorCodeAndErrorDescription;
  // ... 
}

I would have expected something more like:

class ErrType extends ArrayList<ErrTypeEntry> {}
class ErrTypeEntry {
  protected String errorCode
  protected String errorDescription;
}

Okay, so I guess the answer is: because it does. Combining two fields into a single one seems very undesirable. It removed important structure unnecessarily.

4

1 回答 1

1

我的猜测是,您必须将架构写得更像这样,才能(结构上)更接近您的期望:

<xsd:complexType name="ErrTypeEntry">
  <xsd:sequence>
    <xsd:element name="errorCode" type="xsd:string"/>
    <xsd:element name="errorDescription" type="xsd:string"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Errors">
  <xsd:sequence>
    <xsd:element name="error" type="ErrTypeEntry" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>
于 2012-06-07T21:50:50.717 回答