如何在另一个 XSD 中导入 XSD [英] How to import XSD in Another XSD
问题描述
我正在尝试将 xsd 导入另一个 xsd.我看到一些需要导入的问题.我无法理解网络中提供的解决方案.下面是我的 XSD.
I am attempting to import xsd to another xsd. i am seeing some problems to import. i could not understand the solutions which provided in web. below is my XSD.
我有 HEADER.xsd.这对于所有其他 xsd 都是常见的.
I have HEADER.xsd. it is common for all other xsd's.
HEADER.XSD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Header" type="reqHeader"/>
<xs:complexType name="reqHeader">
<xs:sequence>
<xs:element name="MsgId" type="xs:string" minOccurs="0"/>
<xs:element name="MsgDesc" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
MESSAGE1.XSD
MESSAGE1.XSD
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="" schemaLocation="\resources\xsd\HEADER.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="Header" type="xs:reqHeader" />
<xs:element name="Body">
<xs:complexType>
<xs:sequence>
<xs:element name="User">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Name" minOccurs="1"/>
<xs:element type="xs:int" name="DOB" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这里我试图导入元素调用,因为它对所有 xsd 的 [MESSAGE1.XSD MESSAGE2.XSD 等] 都是通用的.
Here i am trying to import element called since it is common for all xsd's [MESSAGE1.XSD MESSAGE2.XSD and so on].
异常表示:无效:src-resolve.4.2:解析组件xs:reqHeader"时出错.检测到 'xs:reqHeader' 位于命名空间 'http://www.w3.org/2001/XMLSchema',但不能从架构文档 'file:/D:/Projects/workspace/Message/resources/xsd/MESSAGE1.xsd' 中引用来自该命名空间的组件.如果这是不正确的命名空间,则可能需要更改xs:reqHeader"的前缀.如果这是正确的命名空间,则应将适当的import"标记添加到file:/D:/Projects/workspace/Message/resources/xsd/MESSAGE1.XSD".
Exception says : Is not a valid:src-resolve.4.2: Error resolving component 'xs:reqHeader'. It was detected that 'xs:reqHeader' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:/D:/Projects/workspace/Message/resources/xsd/MESSAGE1.xsd'. If this is the incorrect namespace, perhaps the prefix of 'xs:reqHeader' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/D:/Projects/workspace/Message/resources/xsd/MESSAGE1.XSD'.
我的项目结构是:
/src/com
/lib
/resources/xsd/MESSAGE1.XSD
/resources/xsd/MESSAGE1.XSD
请有人帮我解决.
推荐答案
Bingo!在与 XSD 进行了大量斗争后,我发现了一种无错误的方法:
Bingo! After fighting a lot with the XSDs I have found an error free way:
代码如下:
- 您需要将
xs:import
更改为xs:include
- 从
xs 中删除
行namespace=""
和xmlns:xs="http://www.w3.org/2001/XMLSchema"
:include
- You need to change the
xs:import
toxs:include
- Remove the
namespace=""
and thexmlns:xs="http://www.w3.org/2001/XMLSchema"
from thexs:include
line
MESSAGE1.xsd
MESSAGE1.xsd
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="header.xsd" />
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="Header" type="reqHeader" />
<xs:element name="Body">
<xs:complexType>
<xs:sequence>
<xs:element name="User">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Name" minOccurs="1" />
<xs:element type="xs:int" name="DOB" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
HEADER.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Header" type="reqHeader" />
<xs:complexType name="reqHeader">
<xs:sequence>
<xs:element name="MsgId" type="xs:string" minOccurs="0" />
<xs:element name="MsgDesc" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
请根据您本地文件的位置修改 XSD 位置.
Please modify the XSD location according to your local file's location.
希望有帮助!
这篇关于如何在另一个 XSD 中导入 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!