473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML Schema <choice> constraints

Dear XML (Schema) experts,

As an example I have the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ROOT_ELEMENT">
<xs:complexType>
<xs:choice>
<xs:element name="FOO1" type="xs:date"/>
<xs:element name="FOO2" type="xs:dateTime"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Which is fine for my schema validator.

However, if I wanted to have the name of the element appearing under
the root-element to ALLWAYS have the same name (for example FOO,
without a number at the end) regardless of the type of the element I
keep getting (MOST OF THE TIME!) this error message:

"Schema error cos-element-consistent - all types of local element
'FOO' must be consistent".

When I look the situation from the point of an instance document I
don't see how the instance document conforming to this schema with
FOO-element (with varying type) could violate W3C XML recommendation.

SOMETIMES my schema validator gives me green light when in "text mode"
and red light in "graphical mode" of this particular situation (in a
bit more complicated schema instance, though) which seems to me a bug
anyway in this schema validator.

What bothers me is that I dunno which of the two is correct; am I
allowed to have in schema under choice-element two elements declared
with the same name, but different type, or is this not allowed (XML
schema itself is a XML document, too, and two elements with same name
but with different type in the same contextual level is not
allowed...)

I am using XMLSPY Enterprise Edition version 2004 rel.2. as the
"schema validator" I was referring to a couple of times.

Appreciate any solid opinions on this,

<kimmo/>
Jul 20 '05 #1
3 4532


Kimmo J?rvikangas wrote:

As an example I have the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ROOT_ELEMENT">
<xs:complexType>
<xs:choice>
<xs:element name="FOO1" type="xs:date"/>
<xs:element name="FOO2" type="xs:dateTime"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Which is fine for my schema validator.

However, if I wanted to have the name of the element appearing under
the root-element to ALLWAYS have the same name (for example FOO,
without a number at the end) regardless of the type of the element I
keep getting (MOST OF THE TIME!) this error message:

"Schema error cos-element-consistent - all types of local element
'FOO' must be consistent".

When I look the situation from the point of an instance document I
don't see how the instance document conforming to this schema with
FOO-element (with varying type) could violate W3C XML recommendation.


Well the W3C XML schema specification is not an attempt to reformulate
the already existing XML recommendation, of course the schema
specification imposes restrictions that go beyond the XML recommendation.

In my view the problem with having

<xs:choice>
<xs:element name="FOO" type="xs:date"/>
<xs:element name="FOO" type="xs:dateTime"/>
</xs:choice>

is that then any schema aware parser trying to process an instance can't
decide which type a <FOO> element occuring is supposed to have.

What you could do however is define a union of date and dateTime e.g.

<xs:simpleType name="date-or-dateTime">
<xs:union memberTypes="xs:date xs:dateTime" />
</xs:simpleType>

and then you can have

<xs:complexType>
<xs:sequence>
<xs:element name="date" type="date-or-dateTime"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

and an instance with elements alike

<date>2004-06-18</date>
<date>2004-06-18T13:33:01</date>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
ki***************@kolumbus.fi (Kimmo J?rvikangas) wrote in message news:<16*************************@posting.google.c om>...
Dear XML (Schema) experts,

As an example I have the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ROOT_ELEMENT">
<xs:complexType>
<xs:choice>
<xs:element name="FOO1" type="xs:date"/>
<xs:element name="FOO2" type="xs:dateTime"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Which is fine for my schema validator.

However, if I wanted to have the name of the element appearing under
the root-element to ALLWAYS have the same name (for example FOO,
without a number at the end) regardless of the type of the element I
keep getting (MOST OF THE TIME!) this error message:

"Schema error cos-element-consistent - all types of local element
'FOO' must be consistent".


What about this schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ROOT_ELEMENT">
<xs:complexType>
<xs:choice>
<xs:element name="FOO">
<xs:simpleType>
<xs:union memberTypes="xs:date xs:dateTime"/>
</xs:simpleType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

it would validate the 2 formats "Date" and "DateTime" under the same
name "FOO".
Jul 20 '05 #3
Isabelle, Martin,

Thanks for Your answers.

In this simple case I do agreee that union makes the trick, but I am
afraid I can't use union with complex types (make my day and tell me I
can).

I guess I will simply have to give up the desire (?) to have an
element to appear in instance documents with the same name but various
types - and learn to desire something that fully conforms to W3C
recommendations.

<kimmo/>
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
2
by: nosferatu_1_1 | last post by:
Hi, I would like to create a schema that validate the following xml: <music> <pop/> <rock/> <pop/> </music>
4
by: shaun | last post by:
I should like to allow/disallow values for an attribute based on the value of another attribute e.g if I have a document <character name="snow white" sex="female" hatcolour=""/> <character...
2
by: Jeremy Chapman | last post by:
Populating a typed dataset from xml document: I created an xml schema (attached below), generated a typed dataset from it, and then programatically I tried to populate the typed dataset by...
4
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
1
by: Gerben Abbink | last post by:
In Relax NG, I understand all other group operators (interleave, choice, oneOrMore, zeroOrMore, optional), but what is the purpose of <group>? Can you give an example?
2
by: Aray | last post by:
I googled for it for few houres, but didn't resolve it, any hints will be thinkfull. I want to use the following XSD file to guarantee <element1is unique, but it doesn't work. The following...
1
by: s123 | last post by:
Hi, I am using the sequence tag under the choice tag. the code part of this is : <xs:choice> <xs:sequence> <xs:element name="values" type="ValuesType" minOccurs="0"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.