XML Schemas: Advanced Validation

P

pr

Is it possible to use an XML Schema to ensure that the data in one
attribute is less than or equal to the value in another?

Is it possible, through the use of the <xsd:sequence> or similar, to
ensure than a multiplicity is equal to the value held in another
attribute?

In case anyone is interested, I am storing knitting charts in XML, for
use in a Java application. They are a 2x2 matrix and I store the
number of rows as an attribute of the chart (which is the root
element). Each row is a child element of the chart, but there must be
exactly as many rows as is specified. Storing the size helps my
program to process the file into an array. I also want to store
certain data about the columns in the chart, these are referred to as
a number and of course this number must be less than or equal to the
total number of columns.
 
J

Joseph Kesselman

Is it possible to use an XML Schema to ensure that the data in one
attribute is less than or equal to the value in another?

Is it possible, through the use of the <xsd:sequence> or similar, to
ensure than a multiplicity is equal to the value held in another
attribute?

No, and no. Cross-validation constraints are not currently handled by
XML Schema with the exception of key/keyref and id/idref. Implement
those in your application code. Think of schema as higher-level syntax
constraints; your application is responsible for semantics.

(Some of the alternative schema languages do support cross-constaints,
but of course those have the issue of not being as widely supported or,
in some sense, as "official". Rumor has it that a future version of XML
Schema is considering picking up some of those capabilites, but I don't
know how real that is or what its status might be.)
 
M

Martin Honnen

Is it possible to use an XML Schema to ensure that the data in one
attribute is less than or equal to the value in another?

Not with the W3C XML schema language.
Is it possible, through the use of the <xsd:sequence> or similar, to
ensure than a multiplicity is equal to the value held in another
attribute?

What is a multiplicity? If you want to make sure a value in one element
or attribute is the same as the value in another element or attribute
then you can use xs:key/keyref to specify that constraint.
 
P

pr

Not with the W3C XML schema language.


What is a multiplicity? If you want to make sure a value in one element
or attribute is the same as the value in another element or attribute
then you can use xs:key/keyref to specify that constraint.

By mutltiplicity, I mean how many child elements are related to the
parent element. And I don't want to make two attributes the same,
just place a constraint on one that it is less than the other.

It looks like its not possible to do these things which is fine, I
will use the schema for gross validation and do the more complex stuff
in my application. Thanks for the replies, folks.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top