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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20046452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:39:53  来源:igfitidea点击:

How to merge more than one XSD file to one XSD file?

javaxmlxsd

提问by Vinayak

I am not master in XML and XSD.

我不是 XML 和 XSD 的高手。

Just want to know how I can merge more than one XSD file to one XSD file?

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

Thanks in Advance.

提前致谢。

采纳答案by halfbit

You can use import(different namespace) and include(same namespace) multiple times. redefinecan also be used multiple times. It depends on what you mean by "merge."

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

See also http://www.herongyang.com/XML-Schema/Multiple-XSD-Schema-Document-Include-Redefine-Import.htmlor http://msdn.microsoft.com/en-us/library/ee254473%28v=bts.10%29.aspx.

另请参阅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

Edit: redefine can be used multiple times (similar to include).

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

Examples (validated in Eclipse) follow. I used different namespace (as the "merging" target namespace) and element names where necessary:

示例(在 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>

...a.xsd:

....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>

...b.xsd: Same as ...a.xsd but target namespace .../b

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

...c.xsd: Same as ...a.xsd but target namespace .../m

...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>

...d.xsd: Same as ...c.xsd but element name b.

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

...e.xsd: Same as ...c.xsd but element name e.

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

...f.xsd: Same as ...c.xsd but element name f.

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