Reputation: 48865
It's getting error prone and I don't like it. Can I store the common tags in a third separate XSD?
I have two XSD files that share most of the tag definitions (38 tags). Each file has other unique tags (1 tag and 2 tags), so the files have 39 tags (38 + 1), and 40 tags (38 + 2) respectively.
Every time I edit a common tag I need to make sure I make the same changes on both files the exact same way... and it's not quite easy anymore.
I was wondering if I could store the common tags in a third "common" XSD, and somehow "include" them in both main files.
This is my [simplified] case:
File "a.xsd":
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="generation-model">
<xsd:attribute name="base-dir" type="xsd:string" use="required" />
</xsd:complexType>
<!-- +38 common tags here -->
</xsd:schema>
File "b.xsd":
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="main-unit">
<xsd:attribute name="identifier" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="set">
<xsd:attribute name="value" type="xsd:string" use="required" />
</xsd:complexType>
<!-- +38 common tags here -->
</xsd:schema>
Anyway, in case of emergency -- if there's no way of doing this -- I'm considering just concatenating file fragments. Ugly but I guess will work.
Upvotes: 1
Views: 203
Reputation: 2605
You could create a third XSD file,that stores the common elements. Then you can use either Xsd Import or XSD Include to add the common elements to each of the separate two files. If the same namespace is used then XSD Include should be used. For a different namespace xsd import is suitable.
An example is available here: Example
Update based on the comment of The Impaler:
The include
tags must be first in place before the custom tags of the XSD. An approach that works is to move the include
to the top of the XSD.
Also while using JAXB it was required to implement an LSResourceResolver
and an LSInput
to resolve the "external" common XSD resource file, that is actually located inside the single JAR file of the application.
Upvotes: 1