如何将多个 XSD 文件合并为一个 XSD 文件?

Vin*_*yak 5 java xml xsd

我不是 XML 和 XSD 的高手。

只是想知道如何将多个 XSD 文件合并为一个 XSD 文件?

提前致谢。

hal*_*bit 3

您可以多次使用import(不同的命名空间)和include (同一命名空间)。redefine也可以多次使用。这取决于您所说的“合并”是什么意思。

另请参阅http://www.herongyang.com/XML-Schema/Multiple-XSD-Schema-Document-Include-Redefine-Import.htmlhttp://msdn.microsoft.com/en-us/library/ee254473% 28v=bts.10%29.aspx

编辑:重新定义可以多次使用(类似于包含)。

下面是示例(在 Eclipse 中验证)。我在必要时使用了不同的名称空间(作为“合并”目标名称空间)和元素名称:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/m"
    xmlns:tns="http://www.example.org/m" elementFormDefault="qualified">

    <!-- import: different (i.e. not target) namespace -->
    <import namespace="http://www.example.org/a" schemaLocation="so20046640a.xsd"/>
    <import namespace="http://www.example.org/b" schemaLocation="so20046640b.xsd"/>

    <!-- include: same namespace -->
    <include schemaLocation="so20046640c.xsd"/>
    <include schemaLocation="so20046640d.xsd"/>

    <!-- redefine: same namespace -->
    <redefine schemaLocation="so20046640e.xsd"/>
    <redefine schemaLocation="so20046640f.xsd"/>
</schema>
Run Code Online (Sandbox Code Playgroud)

...a.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/a"
    xmlns:tns="http://www.example.org/a" elementFormDefault="qualified">
    <element name="a" type="int"/>
</schema>
Run Code Online (Sandbox Code Playgroud)

...b.xsd:与 ...a.xsd 相同,但目标命名空间 .../b

...c.xsd:与 ...a.xsd 相同,但目标命名空间 .../m

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/m"
    xmlns:tns="http://www.example.org/m" elementFormDefault="qualified">
    <element name="a" type="int"/>
</schema>
Run Code Online (Sandbox Code Playgroud)

...d.xsd:与 ...c.xsd 相同,但元素名称

...e.xsd:与 ...c.xsd 相同,但元素名称为 e。

...f.xsd:与 ...c.xsd 相同,但元素名称为 f。