Re: Context Sensitive Element Definitions in W3C XSD Schema?
Michael Kay <[email protected]> Sun, 25 Aug 2013 20:46:57 +0100
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_0E13E0D0-47D4-4933-ADAA-F8D02CDB5416
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=iso-8859-1
On 24 Aug 2013, at 03:27, Steve Batides wrote:
> Is this email address the equivalent of a forum post?
The list description is "Public discussion forum for implementors and =
users of W3C XML Schema", so yes, you can use it that way.
>=20
> I know of know way to achieve this with the W3C schema rec 1.0 and =
I've always assumed it's impossible, but it's been such a pain for so =
long I thought I should at least ask if anyone knew of some clever way =
to achieve it. I havent read the 1.1 rec, but I believe it has some sort =
of context-based defns allowed. Unfortunately, I am not in a situation =
to be using 1.1 with any of our clients, so what I can do with 1.0 is =
all I have to work with.
>=20
> Basically I need to define a hierarchical set of IF/ELSE/ELSEIF =
elements that can be used to contain children, and I need the children =
allowed to be whatever elements are allowed inside the *PARENT* of the =
IF. Because the IF/ELSE/ELSEIF can occur inside most elements in the =
schema, all of which have quite different content models, the only way =
that I know of to support these requirements is to allow IF/ELSE/ELSEIF =
to contain just about anything in the overall schema. That is bad for =
obvious reasons; it allows tons of stuff to be populated where it really =
has no business existing because the IF/ELSE/ELSEIF allows so much.
>=20
> Does anyone know of any way to effectively have an element (in this =
case IF/ELSE/ELSEIF) mimic the content model of it's parent to support =
the requirements above, while only allowing elements that really =
"belong" as 'grandchildren'?
If you define these as local elements then their content model can =
depend on where they occur. For example you can define a type like this
<xs:complexType name=3D"someType">
<xs:choice>
(something)
<xs:element name=3D"if" type=3D"someType"/>
....
<xs:complexType name=3D"someOtherType">
<xs:choice>
(something)
<xs:element name=3D"if" type=3D"someOtherType"/>
Michael Kay
Saxonica
--Apple-Mail=_0E13E0D0-47D4-4933-ADAA-F8D02CDB5416
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
charset=iso-8859-1
<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 24 Aug 2013, at 03:27, Steve Batides wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<div text="#000000" bgcolor="#ffffff">
Is this email address the equivalent of a forum post?<br></div></blockquote><div><br></div>The list description is "<span style="color: rgb(0, 0, 0); font-family: sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; ">Public discussion forum for implementors and users of W3C XML Schema", so yes, you can use it that way.</span><br><blockquote type="cite"><div text="#000000" bgcolor="#ffffff">
<br>
I know of know way to achieve this with the W3C schema rec 1.0 and
I've always assumed it's impossible, but it's been such a pain for
so long I thought I should at least ask if anyone knew of some
clever way to achieve it. I havent read the 1.1 rec, but I believe
it has some sort of context-based defns allowed. Unfortunately, I am
not in a situation to be using 1.1 with any of our clients, so what
I can do with 1.0 is all I have to work with.<br>
<br>
Basically I need to define a hierarchical set of IF/ELSE/ELSEIF
elements that can be used to contain children, and I need the
children allowed to be whatever elements are allowed inside the
*PARENT* of the IF. Because the IF/ELSE/ELSEIF can occur inside most
elements in the schema, all of which have quite different content
models, the only way that I know of to support these requirements is
to allow IF/ELSE/ELSEIF to contain just about anything in the
overall schema. That is bad for obvious reasons; it allows tons of
stuff to be populated where it really has no business existing
because the IF/ELSE/ELSEIF allows so much.<br>
<br>
Does anyone know of any way to effectively have an element (in this
case IF/ELSE/ELSEIF) mimic the content model of it's parent to
support the requirements above, while only allowing elements that
really "belong" as 'grandchildren'?
</div></blockquote><br></div><div>If you define these as local elements then their content model can depend on where they occur. For example you can define a type like this</div><div><br></div><div><xs:complexType name="someType"></div><div> <xs:choice></div><div> (something)</div><div> <xs:element name="if" type="someType"/></div><div> ....</div><div><br></div><div><div><xs:complexType name="someOtherType"></div><div> <xs:choice></div><div> (something)</div><div> <xs:element name="if" type="someOtherType"/></div></div><div><br></div><div>Michael Kay</div><div>Saxonica</div><br></body></html>
--Apple-Mail=_0E13E0D0-47D4-4933-ADAA-F8D02CDB5416--