Re: Attribute groups

Hi Naren,

>>   - Express as much as you can in XML Schema, then use Schematron or
>>     another schema adjunct to express the co-occurrence constraint.
>
> Is above a practical suggestion from a systems development
> perspective.

Others probably have more practical experience than I do, but I
imagine it's probably trickier during the development stage than it is
within a finished application. During development, every time you
change Schematron within the XML Schema, you need to extract the
Schematron schema from the XML Schema, and run a meta-stylesheet on the
Schematron schema to create a validating stylesheet. Depending on what
you want to happen if the document is invalid according to a
Schematron rule, you might need to create your own meta-stylesheet to
use rather than using one of the existing ones, although the existing
RDF probably gives you reasonable programmatic access to the results.

> Do you have a small example of how to achieve this ?

Taking the example that Corey stated:

  in other words, if the attrOne attribute is supplied, an attrTwo
  attribute may optionally be supplied. If attrOne is not supplied,
  attrTwo CANNOT be supplied, but the document remains valid if
  neither is supplied.

The Schematron rule would be:

  <sch:rule context="elementOne">
    <sch:report test="@attrTwo and not(@attrOne)">
      There's an attrTwo attribute, but no attrOne attribute!
    </sch:report>
  </sch:rule>

You can embed that into an XML Schema within a sch:pattern within a
xs:appinfo. For example:

<xs:element name="elementOne">
  <xs:annotation>
    <xs:appinfo>
      <sch:pattern name="elementOne">
        <sch:rule context="elementOne">
          <sch:report test="@attrTwo and not(@attrOne)">
            There's an attrTwo attribute, but no attrOne attribute!
          </sch:report>
        </sch:rule>
      </sch:pattern>
    </xs:appinfo>
  </xs:annotation>
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="attrOne" type="xs:string" />
        <xs:attribute name="attrTwo" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Validating a document against this schema using Topologi's schema
validator, for example, gives you a report about the Schematron
validity as well as the XML Schema validity.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Friday, 15 March 2002 12:01:57 UTC