我正在使用 Netbeans 8.0.1 和JDK 1.7将xsd文件编译为Java类。 xsd包含名称空间xmlns:soapenv
和xmlns:soapenc
,因此编译器也会生成
org.xmlsoap.schemas.soap.encoding
和org.xmlsoap.schemas.soap.envelope
个包。
问题是,org.xmlsoap.schemas.soap.encoding
内部包含了ID.java
类
生成包含两个@XmlID
注释,当我尝试解组时,我得到:
异常说明:尝试设置多个XmlID 类[org.xmlsoap.schemas.soap.encoding.ID]上的属性。属性 [value]不能设置为XmlID,因为已经设置了property [id] 作为XmlID。 - 链接异常:[Exception [EclipseLink-50030](Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JAXBException异常 说明:尝试设置多个XmlID属性 在类[org.xmlsoap.schemas.soap.encoding.ID]上。适当的价值] 不能设置为XmlID,因为property [id]已设置为 XmlID。]
作为一种解决方法,我从value属性中删除了@XmlID
注释,并且解组工作正常。我应该怎么做?
以下是生成的 ID.java 类:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.5-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
package org.xmlsoap.schemas.soap.encoding;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
/**
* <p>Java class for ID complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="ID">
* <simpleContent>
* <extension base="<http://www.w3.org/2001/XMLSchema>ID">
* <attGroup ref="{http://schemas.xmlsoap.org/soap/encoding/}commonAttributes"/>
* <anyAttribute processContents='lax' namespace='##other'/>
* </extension>
* </simpleContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ID", propOrder = {
"value"
})
public class ID {
@XmlValue
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@XmlSchemaType(name = "ID")
protected java.lang.String value;
@XmlAttribute(name = "id")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@XmlSchemaType(name = "ID")
protected java.lang.String id;
@XmlAttribute(name = "href")
@XmlSchemaType(name = "anyURI")
protected java.lang.String href;
@XmlAnyAttribute
private Map<QName, java.lang.String> otherAttributes = new HashMap<QName, java.lang.String>();
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link java.lang.String }
*
*/
public java.lang.String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link java.lang.String }
*
*/
public void setValue(java.lang.String value) {
this.value = value;
}
/**
* Gets the value of the id property.
*
* @return
* possible object is
* {@link java.lang.String }
*
*/
public java.lang.String getId() {
return id;
}
/**
* Sets the value of the id property.
*
* @param value
* allowed object is
* {@link java.lang.String }
*
*/
public void setId(java.lang.String value) {
this.id = value;
}
/**
* Gets the value of the href property.
*
* @return
* possible object is
* {@link java.lang.String }
*
*/
public java.lang.String getHref() {
return href;
}
/**
* Sets the value of the href property.
*
* @param value
* allowed object is
* {@link java.lang.String }
*
*/
public void setHref(java.lang.String value) {
this.href = value;
}
/**
* Gets a map that contains attributes that aren't bound to any typed property on this class.
*
* <p>
* the map is keyed by the name of the attribute and
* the value is the string value of the attribute.
*
* the map returned by this method is live, and you can add new attribute
* by updating the map directly. Because of this design, there's no setter.
*
*
* @return
* always non-null
*/
public Map<QName, java.lang.String> getOtherAttributes() {
return otherAttributes;
}
}
UPDATE - xml架构的精简版
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:me-org:custom-3-1"
targetNamespace="urn:me-org:custom-3-1"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
<!-- SOAP Header Elements -->
<xs:element name="ID">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="soapenv:mustUnderstand" use="required" fixed="1"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="HoldRequests">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:boolean">
<xs:attribute ref="soapenv:mustUnderstand" use="required" fixed="1"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- Type definitions -->
<xs:complexType name="DeviceIdStruct">
<xs:sequence>
<xs:element name="Manufacturer">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="OUI">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="6"/>
<xs:pattern value="[0-9A-F]{6}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ProductClass">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="SerialNumber">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParameterValueStruct">
<xs:sequence>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="256"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Value" type="xs:anySimpleType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParameterValueList">
<xs:complexContent>
<xs:restriction base="soapenc:Array">
<xs:sequence>
<xs:element name="ParameterValueStruct" type="tns:ParameterValueStruct" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="soapenc:arrayType" use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="CommandKeyType">
<xs:restriction base="xs:string">
<xs:maxLength value="32"/>
</xs:restriction>
</xs:simpleType>
<!-- messages -->
<!-- Send -->
<xs:element name="Send">
<xs:annotation>
<xs:documentation>SendMessage </xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="DeviceId" type="tns:DeviceIdStruct"/>
<xs:element name="MaxEnvelopes" type="xs:unsignedInt"/>
<xs:element name="CurrentTime" type="xs:dateTime"/>
<xs:element name="ParameterList" type="tns:ParameterValueList"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- MessageResponse -->
<xs:element name="MessageResponse">
<xs:annotation>
<xs:documentation>MessageResponse</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="MaxEnvelopes" type="xs:unsignedInt"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
由于