XML Schema "logic"?

S

Sean LeBlanc

I'm trying to discern whether XML Schema can do something like this:

Supposing the element has two attributes, id and value.

Now, if id = one value, say "number" vs. another value, say, "alpha",
can I write XML Schema that would limit the values of the attribute
"value" to
1, 2, or 3 if id is number vs. a, b, or c if id is alpha?

I'm trying to tell whether I have to resort to Schematron to do
something like this.

Thanks in advance,
 
J

Joseph Kesselman

If you want cross-constraints on separate values, XML schema doesn't do
that.

In schemas, the right answer would be to use two different kinds of
element rather than one with an ID attribute that toggles it between two
different value ranges. Attributes should be used for annotation to
enhance meaning, not to change meaning.
 
J

Joseph Kesselman

In schemas, the right answer would be to use two different kinds of
element rather than one with an ID attribute that toggles it between two
different value ranges. Attributes should be used for annotation to
enhance meaning, not to change meaning.

.... or, alternatively, two different attributes for the two different
value ranges on a single element.
 
S

Sean LeBlanc

Joseph said:
If you want cross-constraints on separate values, XML schema doesn't do
that.

In schemas, the right answer would be to use two different kinds of
element rather than one with an ID attribute that toggles it between two
different value ranges. Attributes should be used for annotation to
enhance meaning, not to change meaning.


Thanks, Joe. I had the feeling that XML Schema doesn't supply that
functionality. Unfortunately, changing the schema (other to be more
restrictive for further validation to "business rules") is not an
option - the output has to conform to a set XML Schema.

Failing being able to do this in XML Schema, would using Schematron be
a viable strategy?
 
J

Joe Kesselman

I haven't used Schematron, so I have no valid opinion. I'd probably
approach it via application code myself, just because I'm used to
rattling off SAX and DOM applications.
 

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,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top