0

我面临 JAXWS 生成的 XML 包含不需要的 xsi:type 和 xsi:schema 标签的问题。我阅读了其他线程,但到目前为止没有一个对我有帮助。就我而言,我只有 WSDL 和 XSD,我正在使用 jaxws-maven-plugin 从 WSDL(包括 XSD)生成代码

1) jaxws-maven-plugin 配置:

            <plugin>
               <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <bindingDirectory>${basedir}/src/main/wsdl</bindingDirectory>
                            <bindingFiles><bindingFile>Booking_normalized/Booking_1.0.1.0.xjb</bindingFile>
                </bindingFiles>
                            <wsdlDirectory>${basedir}/src/main/wsdl</wsdlDirectory>
                            <wsdlFiles>
                                <wsdlFile>Booking_normalized/Booking_1.0.1.0.wsdl</wsdlFile>
                            </wsdlFiles>
                            <target>2.1</target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

2)XSD(在 WSDL 中导入):

    <xs:complexType name="ScheduleQueryType">
        <xs:annotation>
            <xs:documentation>Describes a Schedule</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="start" type="ScheduleQueryTypestart"/>
            <xs:element name="end" type="ScheduleQueryTypeend"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ScheduleQueryTypestart">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                    The start element contains the origin locationCode and departure dateTime
                </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="DateTimeLocationType">
                <xs:attribute name="windowBefore" type="xs:duration" use="optional">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">A period of time that can be applied to another time resulting in an earlier range of time.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="windowAfter" type="xs:duration" use="optional">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">A period of time that can be applied to another time resulting in a later range of time.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ScheduleQueryTypeend">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                    The end element contains the destination locationCode and arrival dateTime.
                </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="DateTimeLocationType">
                <xs:attribute name="windowBefore" type="xs:duration" use="optional">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">A period of time that can be applied to another time resulting in an earlier range of time.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="windowAfter" type="xs:duration" use="optional">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">A period of time that can be applied to another time resulting in a later range of time.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="DateTimeLocationType">
        <xs:annotation>
            <xs:documentation xml:lang="en">Describes DateTime and Location</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="locationCode" minOccurs="0">
                <xs:annotation>
                    <xs:documentation xml:lang="en">Code used to identify a location</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="ota:StringLength1to16">
                            <xs:attribute name="type" type="ota:AlphaNumericStringLength1to8" use="optional">
                                <xs:annotation>
                                    <xs:documentation>Type of location code</xs:documentation>
                                </xs:annotation>
                            </xs:attribute>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="dateTime" type="ota:DateOrDateTimeType">
            <xs:annotation>
                <xs:documentation>Date and optional time</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="locationName" type="ota:StringLength1to64" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">Name of the location</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

3) 生成的 XML:

<ns5:Schedule>
            <ns5:Segment TID="SEG_1" Inventory="FRR">
                <ns2:start xsi:type="ns2:ScheduleQueryTypestart" dateTime="2015-05-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                    <ns2:locationCode type="NLS">FRPLY</ns2:locationCode>
                </ns2:start>
                <ns2:end xsi:type="ns2:ScheduleQueryTypeend" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                    <ns2:locationCode type="NLS">FRLPD</ns2:locationCode>
                </ns2:end>
                <ns2:serviceProvider Code="SNF"/>
                <ns2:identifier>6609</ns2:identifier>
            </ns5:Segment>
        </ns5:Schedule>

正如您在上面所见,在 Generated XML 中,标签 start 和 end 包含 xmlns:xsi 和 xsi:type 标签。我想摆脱他们。有什么建议么?

请注意,生成的 XML 中的其他项目都可以(它们不包含 xsi 前缀)。

这不是简单的类型转换(可以使用 javaType 绑定解决。它更多的是使用复杂类型。这真的是插件问题还是我的 XSD 有问题?

谢谢。

4

1 回答 1

0

显然, start 和 end 类型被用于不止一种类型。对不起,我不能在这里提到整个 XSD,它会更早被发现的。[我们还注意到我们使用的构建器几乎没有问题]。所以 JAXB 不得不把 type 属性加以区分。

发现问题并解决。

谢谢大家。

于 2015-05-06T11:59:29.973 回答