is it legal to name the s:element and s:complexType the same name? you can see the following code, the element and complextype has exactly the same name this is a chunk of wsdl file.
<s:element name="ProcessTaskActionResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ProcessTaskActionResult" type="tns:ProcessTaskActionResponse"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ProcessTaskActionResponse">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="TaskId" type="tns:ArrayOfServerId"/>
<s:element minOccurs="1" maxOccurs="1" name="Success" type="s:boolean"/>
<s:element minOccurs="0" maxOccurs="1" name="ActionPerformedLabel" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Errors" type="tns:ArrayOfString"/>
<s:element minOccurs="1" maxOccurs="1" name="RemovedFromTaskList" type="s:boolean"/>
</s:sequence>
</s:complexType>
Yes, it is legal to have a complex type and element with the same name in an XML Schema.
Since your question is tagged with [java] and [web-services] you may be using JAXB (via JAX-WS) to generate classes from the XML Schema. In that case since a complex type and element (with an anonymous complex type) have the same name you will need to use an external binding file to rename one of the generated classes.
good guess! the JAXB parser thrown a exception, mainly because the naming conflict, my question is if its legal why the JAXB not liking it?
JAXB (JSR-222) converts complex types to Java classes. For named complex types the resulting class name is derived from the complex type name, for anonymous complex types the resulting class name is derived from the enclosing element. In your case this would result in two classes with the same name that JAXB complains about.
Rename Class Corresponding to the XML Element (binding.xml)
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:element[@name='ProcessTaskActionResponse']/complexType">
<jxb:class name="ProcessTaskActionResponseElement"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Rename Class Corresponding to the Complex Type (binding.xml)
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:complexType[@name='ProcessTaskActionResponse']">
<jxb:class name="ProcessTaskActionResponseType"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments