- From: <noah_mendelsohn@us.ibm.com>
- Date: Wed, 30 Nov 2005 09:32:37 -0500
- To: mark@austrics.com.au
- Cc: xmlschema-dev@w3.org
Mark Phillips writes:
> Every element has precisely one attribute called "is", which
> must take one of three values: "atom", "hash" or "list". The
> root element must have is="hash", but all other elements can be
> any of the three, the default being "atom".
As I suspect you've discovered, XML Schema can do this much quite easily.
If you want to be fancy about it you can make a base complex type that
requires the one attribute and then derive types for use with the specific
elements. You can also just declare the types of the elements
individually. If you need help finding a way to do just ask.
> An atom element must only have simple content. A hash element must
> have element content only, moreover it must not have more than one
> child element of the same name. A list element must have element
> content only, this being elements all called "item" (ie it will have
> 0 or more elements, all called "item").
This constraint cannot be expressed in XML Schema, though we certainly are
regularly asked to support it. You are asking for what we call a
value-based co-occurrence constraint. Co-occurrence because it relates
two separate constructs, the attribute and the element. We refer to this
as value-based because the constraint is not on the existence of the
attribute, but rather involves using the value of the attribute to
constraint the content or value of the element.
The Schema WG is certainly considering various means of doing this in
future versions of the Recommendation, though there are some complexities
and I'm not sure whether it will make the cut for the upcoming XML Schema
1.1. While on the one hand we get lots of requests for this, we also get
a lot of pressure from software vendors not to change XML Schema at all.
Balancing those two imperatives can be tricky.
--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------
Dr Mark H Phillips <mark@austrics.com.au>
Sent by: xmlschema-dev-request@w3.org
11/30/2005 02:45 AM
Please respond to mark
To: xmlschema-dev@w3.org
cc: (bcc: Noah Mendelsohn/Cambridge/IBM)
Subject: Can this schema be written in XML Schema?
Hi,
I have a simple schema that I wish to use for XML documents.
I've been reading up on XML Schema, trying to find a way of
expressing my schema using it, but so far have failed. I
suspect it is currently not possible but thought I would ask
on this list. Is it possible, and if not, is XML Schema likely
to support it at some stage?
Let me explain my schema. It has a root element called "root".
Every element has precisely one attribute called "is", which
must take one of three values: "atom", "hash" or "list". The
root element must have is="hash", but all other elements can be
any of the three, the default being "atom". An atom element
must only have simple content. A hash element must have element
content only, moreover it must not have more than one child element
of the same name. A list element must have element content only,
this being elements all called "item" (ie it will have 0 or more
elements, all called "item").
Here is a simple example of a valid xml document:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root is="hash">
<name>Laura Jones</name>
<address is="hash">
<street>123 Trendy Avenue</street>
<suburb>Prestigious Lakes</suburb>
<postcode>4321</postcode>
</address>
<pets is="list">
<item>Ginger</item>
<item>Polly</item>
<item is="hash">
<name>Rover</name>
<breed>Bulldog</breed>
</item>
</pets>
<matrix is="list">
<item is="list">
<item>1</item><item>0</item><item>1</item>
</item>
<item is="list">
<item>0</item><item>1</item><item>0</item>
</item>
<item is="list">
<item>1</item><item>0</item><item>1</item>
</item>
</matrix>
</root>
What I'd like to do, is to define my schema as a "base schema"
which doesn't say anything about the specifics of a particular
structure, but only enforces the simple rules mentioned above.
The idea would then be to take this base schema and add to
it specific rules (for example about "name", "address", "pets"
and "matrix") to form more tied-down schemas.
Nothing I've read about XML-Schema seems to be appropriate for
what I'm trying to achieve. Any help would be much appreciated!
Mark Phillips.
Received on Wednesday, 30 November 2005 14:56:34 UTC