Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

schema, attributes, interdependent restrictions

Question posted by: Marc Hebert (Guest) on June 27th, 2008 07:07 PM

I'm trying to figure out if something is possible to specify and
constrain using a schema. I'll explain using an example.

sample xml:
<person name="John" age="32"/>
<person name="Julie" age="25"/>

In my schema, I'd love to be able to place different restrictions on
the attribute 'age' based on the value of 'name'... so in this
example, I might want to enforce that any entry where name="John"
includes an age attribute that falls between 30-39, and that Julie's
age value is 20-29.

What I tried to do, and is invalid, is define a JohnPerson and
JuliePerson element type, and then specify that I expected a list
(all) of elements having an element name="person" and
type="JohnPerson", "JuliePerson", etc... by the parser rejected that
with "Multiple elements with name 'person', with different types,
appear in the model group."

Any ideas?

Many thanks,
Marc
Bjoern Hoehrmann's Avatar
Bjoern Hoehrmann
Guest
n/a Posts
June 27th, 2008
07:07 PM
#2

Re: schema, attributes, interdependent restrictions
* Marc Hebert wrote in comp.text.xml:
Quote:
>I'm trying to figure out if something is possible to specify and
>constrain using a schema. I'll explain using an example.
>
>sample xml:
><person name="John" age="32"/>
><person name="Julie" age="25"/>
>
>In my schema, I'd love to be able to place different restrictions on
>the attribute 'age' based on the value of 'name'... so in this
>example, I might want to enforce that any entry where name="John"
>includes an age attribute that falls between 30-39, and that Julie's
>age value is 20-29.


This is not possible with XML Schema 1.0. You could check out NVDL (with
multiple XML Schema schemas), RELAX NG, and Schematron (possibly XML
Schema with embedded Schematron), none of which will work in simple XML
Schema 1.0 implementations of course.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

Marc Hebert's Avatar
Marc Hebert
Guest
n/a Posts
June 27th, 2008
07:07 PM
#3

Re: schema, attributes, interdependent restrictions
On May 23, 7:43 pm, Bjoern Hoehrmann <bjo...@hoehrmann.dewrote:
Quote:
* Marc Hebert wrote in comp.text.xml:
>
Quote:
I'm trying to figure out if something is possible to specify and
constrain using a schema. I'll explain using an example.

>
Quote:
sample xml:
<person name="John" age="32"/>
<person name="Julie" age="25"/>

>
Quote:
In my schema, I'd love to be able to place different restrictions on
the attribute 'age' based on the value of 'name'... so in this
example, I might want to enforce that any entry where name="John"
includes an age attribute that falls between 30-39, and that Julie's
age value is 20-29.

>
This is not possible with XML Schema 1.0. You could check out NVDL (with
multiple XML Schema schemas), RELAX NG, and Schematron (possibly XML
Schema with embedded Schematron), none of which will work in simple XML
Schema 1.0 implementations of course.
--
Björn Höhrmann · mailto:bjo...@hoehrmann.de ·http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/


Thanks very much for that info, that saves me a few hours of trying to
do something impossible.

Marc

hugo's Avatar
hugo
Guest
n/a Posts
June 27th, 2008
07:07 PM
#4

Re: schema, attributes, interdependent restrictions
test
"Marc Hebert" <hebert.marc@gmail.comwrote in message
news:5539b376-9c63-4aff-ad3d-c37993974523@34g2000hsh.googlegroups.com...
Quote:
>
I'm trying to figure out if something is possible to specify and
constrain using a schema. I'll explain using an example.
>
sample xml:
<person name="John" age="32"/>
<person name="Julie" age="25"/>
>
In my schema, I'd love to be able to place different restrictions on
the attribute 'age' based on the value of 'name'... so in this
example, I might want to enforce that any entry where name="John"
includes an age attribute that falls between 30-39, and that Julie's
age value is 20-29.
>
What I tried to do, and is invalid, is define a JohnPerson and
JuliePerson element type, and then specify that I expected a list
(all) of elements having an element name="person" and
type="JohnPerson", "JuliePerson", etc... by the parser rejected that
with "Multiple elements with name 'person', with different types,
appear in the model group."
>
Any ideas?
>
Many thanks,
Marc




 
Not the answer you were looking for? Post your question . . .
189,759 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors