我有两个XSD文件,我希望具有两个不同的xsd文件的元素,它们具有相同的名称,但具有不同的属性类型。
假设下面是 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>
下面是 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>
xml1和xml2的区别是
<xsd:element name="session" type='xsd:string' minOccurs="1"/>
和
<xsd:element name="session" type='xsd:integer' minOccurs="1"/>
使用xsd文件运行xjc时,我面临以下问题。
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.
我到过versioning和link2的地方
但是我不确定如何实现版本控制和零错误编译。 任何帮助将不胜感激!
更新1: 或者我希望会话元素的类型为整数或字符串
<xsd:element name="session" type='xsd:integer | xsd:string' minOccurs="1"/>