W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2003

Re: DTD

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 26 Sep 2003 08:39:54 +0100
Message-ID: <49563737411.20030926083954@jenitennison.com>
To: "roberto" <roberto@softsite.com.br>
Cc: xmlschema-dev@w3.org

Hi Roberto,

> I have a DTD file that validates my XML. In my XML I have a tag
> called "method" that has these attributes: name, value and
> fixedValue. In that tag method, I need to put name and or value or
> fixedValue, and not both.
 
You can't express this constraint in either DTDs or XML Schema. If you
have a DTD or XML Schema schema already, then the easiest thing to do
is to create a Schematron schema that includes a test for this
constraint:

  <sch:rule context="method">
    <sch:assert test="@value or @fixedValue">
      The method element should have either a value or a fixedValue
      attribute.
    </sch:assert>
    <sch:report test="@value and @fixedValue">
      The method element should not have both a value and a fixedValue
      attribute.
    </sch:report>
  </sch:rule>

Or you could switch to using RELAX NG; the schema (in compact syntax)
would be:

  element method {
    attribute name { text },
    (attribute value { text } |
     attribute fixedValue { text })
  }

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 26 September 2003 03:42:20 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:39 GMT