从 xsd 文件生成一些类后,这些类有问题。@xmlElementRef 与 required="false" 一起使用,并且不允许使用该属性。我正在使用的 .xsd:
<xs:schema xmlns:ns="http://shop.pau.softm.com/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://shop.pau.softm.com/xsd">
<xs:element name="checkOrder">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="order" nillable="true" type="ns:Order"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Order">
<xs:sequence>
<xs:element minOccurs="0" name="addressNumber" type="xs:int"/>
<xs:element minOccurs="0" name="auftragsNummer" type="xs:int"/>
<xs:element minOccurs="0" name="companyNumber" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="condition" nillable="true" type="ns:Condition"/>
<xs:element minOccurs="0" name="currency" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="customerId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="customerReference" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="deliveryAddress" nillable="true" type="ns:Address"/>
<xs:element minOccurs="0" name="deliveryConditions" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="deliveryType" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="endCustomerId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="endCustomerReference" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="error" nillable="true" type="ns:Error"/>
<xs:element minOccurs="0" name="haltDescription" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="haltFlag" type="xs:boolean"/>
<xs:element minOccurs="0" name="keySalesArea" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="openingHours" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="orderItem" nillable="true" type="ns:OrderItem"/>
<xs:element minOccurs="0" name="origin" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="tourNumber" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="type" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="warehouseMan" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="warehouseNumber" type="xs:int"/>
<xs:element minOccurs="0" name="wishedDeliveryDate" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Condition">
<xs:sequence>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="type" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Address">
<xs:sequence>
<xs:element minOccurs="0" name="city" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="country" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="createAddress" type="xs:boolean"/>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="name2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="name3" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="name4" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="street" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="zip" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Error">
<xs:sequence>
<xs:element minOccurs="0" name="code" type="xs:int"/>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="origin" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="type" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="OrderItem">
<xs:sequence>
<xs:element minOccurs="0" name="additionalText" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="additionalText2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="customerProductId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="eanCodeOrderUnit" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="error" nillable="true" type="ns:Error"/>
<xs:element minOccurs="0" name="haltDescriptionItem" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="price" nillable="true" type="xs:decimal"/>
<xs:element minOccurs="0" name="productId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="quantity" type="xs:double"/>
</xs:sequence>
</xs:complexType>
<xs:element name="checkOrderResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ns:Order"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="submitOrder">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="order" nillable="true" type="ns:Order"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="submitOrderResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ns:Order"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
和结果(部分)
package com.softm.pau.shop.xsd;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Address", propOrder = {
"city",
"country",
"createAddress",
"name",
"name2",
"name3",
"name4",
"street",
"zip"
})
public class Address {
@XmlElementRef(name = "city", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> city;
@XmlElementRef(name = "country", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> country;
protected Object createAddress;
@XmlElementRef(name = "name", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> name;
@XmlElementRef(name = "name2", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> name2;
@XmlElementRef(name = "name3", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> name3;
@XmlElementRef(name = "name4", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> name4;
@XmlElementRef(name = "street", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> street;
@XmlElementRef(name = "zip", namespace = "http://shop.pau.softm.com/xsd", type = JAXBElement.class, required = false)
protected JAXBElement<Object> zip;
我怎样才能得到 XmlElement 而不是 XmlElementRef?我必须在 xsd 中更改什么?xsd 是从 wsdl 中提取的,我想使用生成的类来调用 web 服务。
齐格弗里德
好的,这里有一些信息,无法回答我自己的问题......
我正在使用 STS 和 Java6。在我的 build.xml 中编码
<!-- JAXB-->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<fileset dir="lib/ct" includes="*.jar" />
</classpath>
</taskdef>
<target name="gen.java" description="Generates the JAXB business objects">
<xjc destdir="src/gen" extension="true">
<schema dir="conf/webapp/WEB-INF/schema" includes="*.xsd" />
<binding dir="resources" includes="*.xjb" />
</xjc>
</target>
我的 binding.xjb 看起来像
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="../conf/webapp/WEB-INF/schema/wsinapa.xsd" node="/s:schema">
<jxb:bindings node="/s:schema/s:element[@name='AccountStatus']">
<jxb:class name="AccountStatusRequest"/>
</jxb:bindings>
</jxb:bindings>
在 src 目录中有 2 个应该编译的 .xsd。其中一个编译没有错误,另一个没有。两者都是从 wsdl 文件中提取的。
干杯
齐格弗里德