schema, attributes, interdependent restrictions

M

Marc Hebert

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
 
B

Bjoern Hoehrmann

* Marc Hebert wrote in comp.text.xml:
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.
 
M

Marc Hebert

* Marc Hebert wrote in comp.text.xml:




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.

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

Marc
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top