theRoot
theRoot

Reputation: 569

xsd schema file - shows elementName is already defined

I have two XSD files , I want to have elements of two different xsd files with same name but with different property type.

Assume below is xml1.xsd

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.com/wm"
    xmlns="http://www.example.com/wm"
  elementFormDefault="qualified">
    <xsd:element name="testEame1">
        <xsd:annotation>
            <xsd:documentation>       test       </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="id" type='xsd:string' minOccurs="1"/>
                <xsd:element name="session" type='xsd:string' minOccurs="1"/>
            </xsd:sequence>
            <xsd:attribute name="pid" type="xsd:integer" use="required"/>
            <xsd:attribute name="version" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

below is xml2.xsd

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.com/wm"
    xmlns="http://www.example.com/wm"
  elementFormDefault="qualified">
    <xsd:element name="testEame1">
        <xsd:annotation>
            <xsd:documentation>        test       </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="id" type='xsd:string' minOccurs="1"/>
                <xsd:element name="session" type='xsd:integer' minOccurs="1"/>
            </xsd:sequence>
            <xsd:attribute name="pid" type="xsd:integer" use="required"/>
            <xsd:attribute name="version" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

There is difference of xml1 and xml2 is

<xsd:element name="session" type='xsd:string' minOccurs="1"/>

and

<xsd:element name="session" type='xsd:integer' minOccurs="1"/>

while running xjc with xsd files,I'm facing below issue.

C:\Temp\tt>xjc *.xsd
parsing a schema...
[ERROR] 'testEame1' is already defined
  line 17 of file:/C:/Temp/tt/xml2.xsd

[ERROR] (related to above error) the first definition appears here
  line 5 of file:/C:/Temp/tt/xml1.xsd

Failed to parse a schema.

What I visited versioning and link2

But I'm not sure how to implement versioning and compile with zero errors. Any help will be highly appreciated!

UPDATE 1: Or I want to have session element to have type integer or string

<xsd:element name="session" type='xsd:integer | xsd:string' minOccurs="1"/>

Upvotes: 0

Views: 678

Answers (1)

umesh shukla
umesh shukla

Reputation: 171

Your both schema's targetNamespace is same (http://www.example.com/wm). Once try with different targetNamespace for each schema.

Upvotes: 1

Related Questions