is this a job for schematron?
"Peter Aberline" <[email protected]> Tue, 6 Apr 2004 11:53:54 +0100
| Newsgroups | gmane.text.xml.schematron |
|---|---|
| Message-ID | <OFF74E4B5B.A7CCFCC1-ON80256E6E.003BA550-80256E6E.003BDDCD@wcg.co.uk> |
Hi all,
Apologies in advance for the long post. I'm having trouble with a
particular task and it has been suggested that schematron may
be provide a solution to the problem. As I've had no exposure to schematron
I thought I would ask the list if what I want to do is possible before I
start.
I'm trying to write a xsd schema which defines the following document:
<root>
<letters>
<a>A</a>
<dog>DOG<dog>
<b>B</b>
<fish>FISH</fish>
<c>C</c>
</letters>
<letters>
<cat>CAT<cat>
<c>C</c>
<b>B</b>
<a>A</a>
</letters>
<letters>
...
</letters>
</root>
I want my schema to define the following rules:
1: The letters element must contain a, b, and c elements in any order.
2: The letters element can also contain any number of other elements, in
any order, such as dog, cat, fish etc.
I'm having much trouble developing a schema that can enforce both these
rules simultaneously:
Requirement 1 is easy to achieve using the xs:all tag. Unfortunately,
xs:any is not allowed to be a child of xs:all, which makes requirement 2
difficult.
The following schema allows requirement 2, but not 1:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="c"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema allows requirement 1, but not 2:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:all>
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Instead, would it be better to define a schema that allows any elements
under letters, and then use schematron to test if particular elements are
there, and of the correct datatype? Can schematron do this? Any advice
would be greatly appreciated.
many thanks,
Peter
_____________________________________________________________
The information in this email and in any attachments is confidential and
may be privileged. If you are not the intended recipient, please destroy
this message, delete any copies held on your systems and notify the sender
immediately. You should not retain, copy or use this email for any
purpose, nor disclose all or any part of its content to any other person.
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click