[prev in list] [next in list] [prev in thread] [next in thread]
List: xml-dev
Subject: [xml-dev] XSD problem - variable content in foreign namespace
From: Hans-Juergen Rennau <hrennau () yahoo ! de>
Date: 2022-05-31 16:36:26
Message-ID: 1053586414.8653506.1654014986928 () mail ! yahoo ! com
[Download RAW message or body]
Hello,
I stumbled upon an XSD modelling problem, which is probably insolvable, but perhaps I \
overlook something and you might tell me. The larger topic may be summarized \
"Modelling elements in foreign namespaces". Here, "foreign namespace" means a \
namespace different from the namespace of the root element. The root element \
namespace I call the local namespace. Accordingly, I speak of local and foreign XSD. \
Now the *problem*: How to define multiple content models for an element name in a \
foreign namespace? In other words: how to write the XSD so that <x:foo> elements (x \
denoting a foreign namespace) can have different content dependent on where it \
appears. In the following example, <x:foo> has different content dependent on if it's \
a child of <b> or <c>: <a xmlns:x="http://example.com/x"> <b> <y/> \
<x:foo> <x:ONE/> <x:TWO/> </x:foo> \
</b> <c> <y/> <x:foo> <x:ONE/> \
<x:TEN/> </x:foo> </c></a> How to write XSD reflecting \
this? In general, I see two approaches how to model elements in a foreign \
namespace:(1) Element reference - e.g. <xs:element ref="x:foo"/>(2) Imported type - \
e.g. <xs:element name="foo" type="x:footype"/> Limitation of (1): the same reference \
QName means the same thing everywhere, so the document cannot contain <x:foo> \
elements with different content models, dependent on location. Limitation of (2): as \
the type of a complex element describes its *children*, the namespace appears in the \
*children* of the element with the foreign type, not the element itself. So in the \
example, I would have to use a type from namespace x in order to describe <x:foo>'s \
parent - <b> and <c>. This is possible but twisted, as it is more natural to have the \
type definitions for <b> and <c> in the local XSD. Even worse, it gets really \
cumbersome when the element in the foreign namespace has siblings in the local \
namespace, as is the case in the example - note the <y> sibling of <x:foo>. So one \
has to make a wild construction - writing into the foreign XSD types describing local \
elements <b> and <c>, which will have to reference local element declarations or \
element types (example: reference <y>), in order to achieve the mixing of namespaces. \
Mental ping pong. So would you agree that supporting variable content models for \
foreign element QNames is tricky and not straightforward at all - or do I overlook a \
simpler possibility? Thank you for ideas or comments!Hans-Jürgen
PS: Here come the XSDs which I wrote to model the document:
a.xsd:<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" \
xmlns:x="http://example.com/x" xmlns="http://example.com/a" \
targetNamespace="http://example.com/a" elementFormDefault="qualified"> \
<xs:import namespace="http://example.com/x" schemaLocation="x.xsd"/> <xs:element \
name="a"> <xs:complexType> <xs:sequence> <xs:element name="b" type="x:bType"/> \
<xs:element name="c" type="x:cType"/> </xs:sequence> </xs:complexType> </xs:element> \
<xs:element name="y" type="xs:string"/></xs:schema> x.xsd:<xs:schema \
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="http://example.com/a" \
xmlns="http://example.com/x" targetNamespace="http://example.com/x" \
elementFormDefault="qualified"> <xs:import namespace="http://example.com/a" \
schemaLocation="a.xsd"/> <xs:complexType name="bType"> \
<xs:sequence> <xs:element ref="a:y"/> <xs:element \
name="foo"> <xs:complexType> \
<xs:sequence> <xs:element name="ONE"/> \
<xs:element name="TWO"/> </xs:sequence> \
</xs:complexType> </xs:element> \
</xs:sequence> </xs:complexType> <xs:complexType \
name="cType"> <xs:sequence> <xs:element ref="a:y"/> \
<xs:element name="foo"> <xs:complexType> \
<xs:sequence> <xs:element name="ONE"/> \
<xs:element name="TEN"/> </xs:sequence> \
</xs:complexType> </xs:element> </xs:sequence> \
</xs:complexType></xs:schema>
[Attachment #3 (text/html)]
<html><head></head><body><div class="yahoo-style-wrap" style="font-family:Helvetica \
Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div dir="ltr" \
data-setdir="false">Hello,</div><div dir="ltr" data-setdir="false"><br></div><div \
dir="ltr" data-setdir="false">I stumbled upon an XSD modelling problem, which is \
probably insolvable, but perhaps I overlook something and you might tell \
me.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" \
data-setdir="false">The larger topic may be summarized "Modelling elements in foreign \
namespaces". Here, "foreign namespace" means a namespace different from the \
namespace of the root element. The root element namespace I call the local namespace. \
Accordingly, I speak of local and foreign XSD.</div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Now the *problem*: \
How to define multiple content models for an element name in a foreign \
namespace?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" \
data-setdir="false">In other words: how to write the XSD so that <x:foo> \
elements (x denoting a foreign namespace) can have different content dependent on \
where it appears. In the following example, <x:foo> has different content \
dependent on if it's a child of <b> or <c>:</div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><div><div><div \
dir="ltr" data-setdir="false"><a \
xmlns:x="http://example.com/x"></div><div> <b></div><div \
dir="ltr" data-setdir="false"> <y/></div><div \
dir="ltr" data-setdir="false"> <x:foo></div><div \
dir="ltr" data-setdir="false"> \
<x:ONE/></div><div dir="ltr" data-setdir="false"> \
<x:TWO/></div><div dir="ltr" data-setdir="false"> \
</x:foo> \
</div><div> </b></div><div dir="ltr" \
data-setdir="false"> <c></div><div dir="ltr" \
data-setdir="false"> <y/></div><div dir="ltr" \
data-setdir="false"> <x:foo></div><div dir="ltr" \
data-setdir="false"> \
<x:ONE/></div><div dir="ltr" data-setdir="false"> \
<x:TEN/></div><div dir="ltr" data-setdir="false"> \
</x:foo> </div><div dir="ltr" \
data-setdir="false"> </c></div><div></a></div></div><div \
dir="ltr" data-setdir="false"><br style="color: rgb(0, 0, 0); font-family: \
"Helvetica Neue", Helvetica, Arial, sans-serif;"></div></div>How to write \
XSD reflecting this?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" \
data-setdir="false">In general, I see two approaches how to model elements in a \
foreign namespace:</div><div dir="ltr" data-setdir="false">(1) Element reference - \
e.g. <xs:element ref="x:foo"/></div><div dir="ltr" data-setdir="false">(2) \
Imported type - e.g. <xs:element name="foo" type="x:footype"/></div><div \
dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Limitation \
of (1): the same reference QName means the same thing everywhere, so the document \
cannot contain <x:foo> elements with different content models, dependent on \
location.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" \
data-setdir="false">Limitation of (2): as the type of a complex element describes its \
*children*, the namespace appears in the *children* of the element with the foreign \
type, not the element itself. So in the example, I would have to use a type from \
namespace x in order to describe <x:foo>'s parent - <b> and <c>. \
This is possible but twisted, as it is more natural to have the type definitions for \
<b> and <c> in the local XSD. Even worse, it gets really cumbersome when \
the element in the foreign namespace has siblings in the local namespace, as is the \
case in the example - note the <y> sibling of <x:foo>. So one has to make \
a wild construction - writing into the foreign XSD types describing local elements \
<b> and <c>, which will have to reference local element declarations or \
element types (example: reference <y>), in order to achieve the mixing of \
namespaces. Mental ping pong. </div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false">So would you agree \
that supporting variable content models for foreign element QNames is tricky and not \
straightforward at all - or do I overlook a simpler possibility?</div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thank you for ideas \
or comments!</div><div dir="ltr" data-setdir="false">Hans-Jürgen</div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false">PS: Here come the \
XSDs which I wrote to model the document:</div><div dir="ltr" \
data-setdir="false"><br></div><div dir="ltr" data-setdir="false">a.xsd:</div><div \
dir="ltr" data-setdir="false"><div><div><xs:schema \
xmlns:xs="http://www.w3.org/2001/XMLSchema" </div><div><span style="white-space: \
pre-wrap;"> </span> \
xmlns:x="http://example.com/x" xmlns="http://example.com/a"<span \
style="white-space: pre-wrap;"> </span> </div><div><span \
style="white-space: pre-wrap;"> </span> \
targetNamespace="http://example.com/a" </div><div><span \
style="white-space: pre-wrap;"> </span> \
elementFormDefault="qualified"></div><div><span style="white-space: \
pre-wrap;"> </span><xs:import namespace="http://example.com/x" \
schemaLocation="x.xsd"/></div><div><span style="white-space: \
pre-wrap;"> </span></div><div><span style="white-space: \
pre-wrap;"> </span><xs:element name="a"></div><div><span style="white-space: \
pre-wrap;"> </span><xs:complexType></div><div><span style="white-space: \
pre-wrap;"> </span><xs:sequence></div><div><span style="white-space: \
pre-wrap;"> </span><xs:element name="b" type="x:bType"/></div><div><span \
style="white-space: pre-wrap;"> </span><xs:element name="c" \
type="x:cType"/></div><div><span style="white-space: \
pre-wrap;"> </span></xs:sequence></div><div><span style="white-space: \
pre-wrap;"> </span></xs:complexType></div><div><span style="white-space: \
pre-wrap;"> </span></xs:element><span style="white-space: \
pre-wrap;"> </span></div><div><span style="white-space: \
pre-wrap;"> </span><xs:element name="y" \
type="xs:string"/></div><div></xs:schema></div><div><br></div></div>x.xsd:</div><div \
dir="ltr" data-setdir="false"><div><div><xs:schema \
xmlns:xs="http://www.w3.org/2001/XMLSchema" </div><div> \
xmlns:a="http://example.com/a" xmlns="http://example.com/x" \
</div><div> \
targetNamespace="http://example.com/x" </div><div> \
elementFormDefault="qualified"></div><div> <xs:import \
namespace="http://example.com/a" schemaLocation="a.xsd"/></div><div> \
</div><div> <xs:complexType \
name="bType"></div><div> \
<xs:sequence></div><div> \
<xs:element ref="a:y"/></div><div> \
<xs:element name="foo"></div><div> \
<xs:complexType></div><div> \
<xs:sequence></div><div> \
<xs:element \
name="ONE"/></div><div> \
<xs:element name="TWO"/></div><div> \
\
</xs:sequence></div><div> \
</xs:complexType> \
</div><div> \
</xs:element></div><div> </xs:sequence> \
</div><div> \
</xs:complexType></div><div> </div><div> \
<xs:complexType name="cType"></div><div> \
<xs:sequence></div><div> \
<xs:element ref="a:y"/></div><div> \
<xs:element name="foo"></div><div> \
<xs:complexType></div><div> \
<xs:sequence></div><div> \
<xs:element \
name="ONE"/></div><div> \
<xs:element name="TEN"/></div><div> \
\
</xs:sequence></div><div> \
</xs:complexType></div><div> \
</xs:element></div><div> </xs:sequence> \
</div><div> \
</xs:complexType></div><div></xs:schema></div><div><br></div></div><br></div><div \
dir="ltr" data-setdir="false"><br></div></div></body></html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic