Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSD unordered sequence with undefined elements ignored

Reply
Thread Tools

XSD unordered sequence with undefined elements ignored

 
 
klikic
Guest
Posts: n/a
 
      01-14-2007
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

 
Reply With Quote
 
 
 
 
klikic
Guest
Posts: n/a
 
      01-14-2007
I am sorry I made a mistake:
element in XML is not recurEnd but endRecur.

> <Recur>
> <ignoredElement>saasda</ignoredElement>
> <frequency>sdsad</frequency>
> <recurEnd>kjdskdj</recurEnd>
> </Recur>


 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      01-15-2007
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 xmlnss="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
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsd:sequence with mixed child elements craig.milley@gmail.com XML 4 08-27-2007 02:57 PM
Unordered tree to store elements of a parenthesized expression Kaushik Java 5 01-08-2007 07:42 AM
Undefined elements XSD definition oziris XML 3 11-24-2005 12:27 PM
Mixing ordered and unordered elements yann XML 1 08-19-2005 09:43 PM
unordered elements in DTD example...bogus? Ha XML 1 01-28-2004 04:21 AM



Advertisments