1

我有以下 XSD,我正在从中生成 JAXB 绑定...(仅留下此问题的相关部分):

<?xml version="1.0"?>
<xsd:schema 
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
          jaxb:extensionBindingPrefixes="simplify">...
 <xsd:element name="trace">

     <xsd:annotation>

        <xsd:documentation>
            containing screen navigation data
        </xsd:documentation>

    </xsd:annotation>

    <xsd:complexType>

        <xsd:choice minOccurs ="0" maxOccurs ="unbounded">
            <xsd:element ref="time"  />
            <xsd:element ref="event" />
            <xsd:element ref="location" />
            <xsd:element minOccurs="0" ref="index" ></xsd:element>
            <xsd:element minOccurs="0" ref="caseId"/>
            <xsd:element minOccurs="0" ref="contactAttId" />
            <xsd:element minOccurs="0" ref="action" />
        </xsd:choice>
    </xsd:complexType>
</xsd:element>
4

1 回答 1

1

您可以使用以下架构

  <xsd:simpleType name="LayerRate_T">
    <xsd:annotation>
       <xsd:appinfo>
          <xjc:javaType name="org.acme.foo.LayerRate"  adapter="org.acme.foo.LayerRateAdapter" />
       </xsd:appinfo>
    </xsd:annotation>
  </xsd:simpleType>

相反,当您将绑定配置包含到您的 XSD 中时,当您使用外部绑定时是不同的。

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="2.1">
    <jaxb:bindings schemaLocation="compass_input_spec_12122014.xsd" node="/xsd:schema">
        <jaxb:bindings node="//xsd:element[@name='trace']/xsd:complexType">
            <simplify:property name="timeOrEventOrLocation">
                <simplify:as-element-property />
            </simplify:property>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>
于 2014-12-19T08:55:58.780 回答