xsd schema file - shows elementName is already defined

北战南征 提交于 2019-12-11 15:44:49

问题


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"/>

回答1:


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



来源:https://stackoverflow.com/questions/52553972/xsd-schema-file-shows-elementname-is-already-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!