Reputation: 155
I am not master in XML and XSD.
Just want to know how I can merge more than one XSD file to one XSD file?
Thanks in Advance.
Upvotes: 5
Views: 23246
Reputation: 3464
You can use import (different namespace) and include (same namespace) multiple times. redefine can also be used multiple times. It depends on what you mean by "merge."
See also http://www.herongyang.com/XML-Schema/Multiple-XSD-Schema-Document-Include-Redefine-Import.html or http://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:
<?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:
<?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
...c.xsd: Same as ...a.xsd but target namespace .../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.
...e.xsd: Same as ...c.xsd but element name e.
...f.xsd: Same as ...c.xsd but element name f.
Upvotes: 3