JAXB Simplify plugin vs *.xjb

放肆的年华 提交于 2019-12-10 09:31:34

问题


I'm trying to use the Simplify plugin to replace a complex property with a set of simpler ones. I made it working following the plugin's manual. But I can't change the original schema, so I have to use an external bindings.xjb. And it gives me all sort of errors. Does somebody have a working example of a similar thing?

Original 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>

Modified XSD that works for me:

<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>

My bindings.xjb (that I want to use instead of changing the schema):

<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>

My current exception

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:


Ok, I figured this out. Here is the configuration that made it working:

<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>

That simple.



来源:https://stackoverflow.com/questions/17794506/jaxb-simplify-plugin-vs-xjb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!