JAXWS-maven-plugin在生成的xml

时间:2015-05-04 12:52:35

标签: jaxb2 jaxws-maven-plugin

我正面临一个问题,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出了问题?

感谢。

1 个答案:

答案 0 :(得分:0)

显然,开始和结束类型用于多种类型。对不起,我不能在这里提到整个XSD,它早就可以找到了。 [我们还注意到我们使用的构建器几乎没有问题]。因此,JAXB必须将type属性作出区分。

发现并解决了问题。

感谢所有人。