J
joshua.davies
I'm pretty new to XML Schema, so this may not be possible, but I
thought I'd ask... I've got a set of similar documents that have
common headers & footers (but separate "middle parts") - e.g.:
<response1>
<metadata>
<address>127.0.0.1</address>
<id>abc@123</id>
</metadata>
<response1Results>...</response1Results>
<environment>dev</environment>
</response1>
<response2>
<metadata>
<address>127.0.0.1</address>
<id>abc@123</id>
</metadata>
<response2results>...</response2Results>
<environment>dev</environment>
</response2>
So the <metadata> element is the common header, and the <environment>
element is the common footer (obviously simplified for illustration
purposes).
I'm trying to model this using XML schema; since there's a commonality
here, I figured I should create an abstract <complexType> and extend
it in both places. Here's what I tried to do:
<xs:complexType name="CommonResponse" abstract="true">
<xs:sequence>
<xs:element name="metadata" ... />
<xs:element name="environment" ... />
</xs:complexType>
and then extend it when I define the concrete types, like this:
<xs:element name="response1">
<xs:complexType>
<xs:complexContent>
<xs:extension base="CommonResponse">
<xs:sequence>
<xs:element name="response1Results" ... />
....
Xerces rejects this because it expects <response1Results> to appear
after <environment> (which makes sense...) If I change the
<xs:sequence> to <xs:all>, the schema doesn't even parse; I get:
An 'all' model group must appear in a particle with {min occurs} =
{max occurs} = 1, and that particle must be part of a pair which
constitutes the {content type} of a complex type definition.
which I don't really understand...
Is what I'm trying to model impossible to express this way? It's no
big deal if I have to do a bit of duplication, but I'm curious if this
is supported/the "right" way to do things.
thought I'd ask... I've got a set of similar documents that have
common headers & footers (but separate "middle parts") - e.g.:
<response1>
<metadata>
<address>127.0.0.1</address>
<id>abc@123</id>
</metadata>
<response1Results>...</response1Results>
<environment>dev</environment>
</response1>
<response2>
<metadata>
<address>127.0.0.1</address>
<id>abc@123</id>
</metadata>
<response2results>...</response2Results>
<environment>dev</environment>
</response2>
So the <metadata> element is the common header, and the <environment>
element is the common footer (obviously simplified for illustration
purposes).
I'm trying to model this using XML schema; since there's a commonality
here, I figured I should create an abstract <complexType> and extend
it in both places. Here's what I tried to do:
<xs:complexType name="CommonResponse" abstract="true">
<xs:sequence>
<xs:element name="metadata" ... />
<xs:element name="environment" ... />
</xs:complexType>
and then extend it when I define the concrete types, like this:
<xs:element name="response1">
<xs:complexType>
<xs:complexContent>
<xs:extension base="CommonResponse">
<xs:sequence>
<xs:element name="response1Results" ... />
....
Xerces rejects this because it expects <response1Results> to appear
after <environment> (which makes sense...) If I change the
<xs:sequence> to <xs:all>, the schema doesn't even parse; I get:
An 'all' model group must appear in a particle with {min occurs} =
{max occurs} = 1, and that particle must be part of a pair which
constitutes the {content type} of a complex type definition.
which I don't really understand...
Is what I'm trying to model impossible to express this way? It's no
big deal if I have to do a bit of duplication, but I'm curious if this
is supported/the "right" way to do things.