XML Schemas: Advanced Validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pr@paulrichards.me.uk

    XML Schemas: Advanced Validation

    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.

  • Joseph Kesselman

    #2
    Re: XML Schemas: Advanced Validation

    pr@paulrichards .me.uk wrote:
    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.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden

    Comment

    • Martin Honnen

      #3
      Re: XML Schemas: Advanced Validation

      pr@paulrichards .me.uk wrote:
      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.

      --

      Martin Honnen

      Comment

      • pr@paulrichards.me.uk

        #4
        Re: XML Schemas: Advanced Validation

        On 13 Mar, 13:42, Martin Honnen <mahotr...@yaho o.dewrote:
        p...@paulrichar ds.me.uk wrote:
        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.
        >
        --
        >
                Martin Honnen
               http://JavaScript.FAQTs.com/
        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.

        Comment

        Working...