XSD unordered sequence with undefined elements ignored

klikic

Usenet Archive
Joined
Apr 28, 2006
Messages
7
Reaction score
0
Hi.
How can create a unordered sequence with defined elements that can occur ones and "other" elements that are ignored.
Example:
XML:
<Recur>
<ignoredElement>saasda</ignoredElement>
<frequency>sdsad</frequency>
<recurEnd>kjdskdj</recurEnd>
</Recur>

Elements "frequency" and "recurEnd" are not optional and can occur only ones. Element "ignoredElement" or any other element taht is not defined, can occur multiple times or none, and can be at any position (between mandatory elements or at end,...).

I created XSD:
<xs:element name="Recur">
<xs:complexType mixed="false">
<xs:sequence maxOccurs="unbounded">
<xs:element ref="frequency"/>
<xs:element ref="endRecur"/>
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded"//> </xs:sequence> </xs:complexType> </xs:element>

This doesn't work: I have errors while validating XML with XSD. I tried with choice but with same effect. Any help or suggestion would be nice. Thanks.
Alan
 

klikic

Usenet Archive
Joined
Apr 28, 2006
Messages
7
Reaction score
0
I am sorry I made a mistake:
element in XML is not recurEnd but endRecur.
 

George Bina

Usenet Archive
Joined
Jan 30, 2004
Messages
134
Reaction score
0
Hi,

You cannot do that with XML Schema. All you can do is to relax the content model allowing more than what you want, use <xs:choice maxOccurs="unbounded">. If Relax NG does not scare you then look into that. Alternatively you can add a couple of Schematron rules inside XML Schema to enforce one occurrence of frequency and endRecur elements. See below a complete example that uses Schematron embedded rules:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com" xmlns:t="http://www.example.com"> <xs:annotation> <xs:appinfo> <ns xmlns="http://www.ascc.net/xml/schematron" uri="http://www.example.com" prefix="t"/> </xs:appinfo> </xs:annotation> <xs:element name="Recur"> <xs:annotation> <xs:appinfo> <pattern xmlns="http://www.ascc.net/xml/schematron" name="test"> <rule context="t:Recur"> <assert test="count(t:frequency)=1">There should be one occurrence of frequency.</assert> <assert test="count(t:endRecur)=1">There should be one occurrence of endRecur.</assert> </rule> </pattern> </xs:appinfo> </xs:annotation> <xs:complexType mixed="false"> <xs:choice maxOccurs="unbounded"> <xs:element name="frequency" form="qualified" type="xs:string"/> <xs:element name="endRecur" form="qualified"/> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/> </xs:choice> </xs:complexType> </xs:element> </xs:schema>

Best Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top