W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2013

Re: Context Sensitive Element Definitions in W3C XSD Schema?

From: Michael Kay <mike@saxonica.com>
Date: Sun, 25 Aug 2013 20:46:57 +0100
Cc: xmlschema-dev@w3.org, sam moltek <byland@moltek.net>
Message-Id: <175855E7-1A19-443F-8F0C-70678FD43E5A@saxonica.com>
To: batides@moltek.net

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.
> 
> 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.
> 
> 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.
> 
> 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="someType">
  <xs:choice>
    (something)
    <xs:element name="if" type="someType"/>
   ....

<xs:complexType name="someOtherType">
  <xs:choice>
    (something)
    <xs:element name="if" type="someOtherType"/>

Michael Kay
Saxonica


Received on Sunday, 25 August 2013 19:47:21 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:16:05 UTC