java - xsd 模式文件 - 显示 elementName 已定义
问题描述
我有两个 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.
但我不确定如何实现版本控制和零错误编译。任何帮助将不胜感激!
更新1: 或者我想让会话元素具有整数或字符串类型
<xsd:element name="session" type='xsd:integer | xsd:string' minOccurs="1"/>
解决方案
您的两个架构的 targetNamespace 相同(http://www.example.com/wm)。一次尝试为每个模式使用不同的 targetNamespace。
推荐阅读
- git - 在 Git repo(不是 github)上使用 SVN 客户端
- node.js - 从 FTP 下载并直接将其复制到 Azure Blob/Amazon S3 中,而无需将其存储在 Node.js 中的本地系统中
- ios - SwiftUI:动态“列表”中的“切换”在重用时破坏了它们的布局?
- unit-testing - 使用 Mockito 模拟挂起函数返回 null
- c++ - 为什么这个示例 C++ 代码片段中的第一个参数是对象,而不是对象的内存地址?
- c++ - Cin 和 getline 不会正确保存非 ascii 字符
- html - 如何将图像放在容器的顶部中心
- javascript - 空字符串是有效的 JSON 键吗?
- javascript - quick.db 调平系统 - database.updateValue 不是函数
- java - 什么相当于 Flux 中 Mono 的 doOnSuccess 方法?