JAXB简化插件vs * .xjb

时间:2013-07-22 18:14:20

标签: jaxb xsd wsdl xjb jaxb2-simplify-plugin

我正在尝试使用Simplify plugin将一个复杂属性替换为一组更简单的属性。我按照插件的手册开始工作。但我无法更改原始架构,因此我必须使用外部bindings.xjb。它给了我各种错误。有人有类似事情的工作实例吗?

原创XSD:

<xs:schema id="messages"
    elementFormDefault="qualified"
    version="Exchange2010_SP2"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">

<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>

...

<xs:complexType name="ArrayOfResponseMessagesType">
    <xs:choice maxOccurs="unbounded">
        <xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType"/>
        <xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
        <xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>

        ...

    </xs:choice>
</xs:complexType>

修改后的XSD对我有用:

<xs:schema id="messages"
    elementFormDefault="qualified"
    version="Exchange2010_SP2"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:extensionBindingPrefixes="simplify"
    targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">

<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>

...

<xs:complexType name="ArrayOfResponseMessagesType">
    <xs:choice maxOccurs="unbounded">
        <xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType">
          <xs:annotation>
            <xs:appinfo>
              <simplify:as-element-property/>
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
        <xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>

        ...

    </xs:choice>
</xs:complexType>

我的bindings.xjb(我想使用而不是更改架构):

<bindings version="2.1"
      xmlns="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
      extensionBindingPrefixes="simplify">
<bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[@name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
    <xs:annotation>
        <xs:appinfo>
            <simplify:as-element-property/>
        </xs:appinfo>
    </xs:annotation>
</bindings>
</bindings>

我当前的例外

org.xml.sax.SAXParseException: Unsupported binding namespace "http://www.w3.org/2001/XMLSchema". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?

1 个答案:

答案 0 :(得分:4)

好的,我想出来了。以下是使其正常工作的配置:

<bindings version="2.1"
      xmlns="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
      extensionBindingPrefixes="simplify">


  <bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[@name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
    <simplify:as-element-property/>
  </bindings>

</bindings>

那很简单。