我正在尝试使用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"?
最佳答案
好的,我知道了。这是使其生效的配置:
<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>
这么简单。