OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Using <choice> to enforce rules

[ Lists Home | Date Index | Thread Index ]

Hi Sean,

> Hi, Eddie,
>
> Thanks for your suggestion.  Do you know if Xerces 1.4 supports Schematron
> embedded in W3C schema?

No, unfortuantely not. As of today it's only the Schematron Validator that
supports these kinds of embedded Schematron rules. However, you can implement
this yourself by including Xalan (the XSLT package from Xerces) in your
application. The basic idea is to include a couple of XSLT transformations in
your processing chain. First you extract the embedded Schematron rules using the
XSD2Schtrn.xsl [1] stylesheet and then you use that result to validate with the
Schematron stylesheets.
I have a paper in the finishing stages that will give examples and explain the
validation process in detail.

Cheers,
/Eddie

[1] http://www.topologi.com/public/Schtrn_XSD/XSD2Schtrn.zip

>
>
> Sean
>
>                 -----Original Message-----
>                 From:   Eddie Robertsson [mailto:eddie@allette.com.au]
>                 Sent:   Tuesday, February 05, 2002 6:07 PM
>                 To:     Sean Zhang
>                 Cc:     xml-dev@lists.xml.org
>                 Subject:        Re: [xml-dev] Using <choice> to enforce
> rules
>
>                 Hi Sean,
>
>                 > I try to use W3C schema to enforce a business rule so that
> only one of the
>                 > two attributes can have blank value.
>                 >
>                 > My schema structure is one attribute group with two
> attributes which
>                 > requires value, one attribute group with two attributes
> which only first
>                 > attribute requires value and one attribute group with same
> two attributes
>                 > which only second attribute requires value.  Then I have
> two groups (element
>                 > groups), first group have the first and second attribute
> groups and second
>                 > group have first and third attribute group.  Last I create
> the element which
>                 > uses a <choice> with reference to the two element groups.
> The schema and an
>                 > instance document are below.
>                 >
>                 > I created it in XML Spy 4 and it works as expected.  But
> when I use Java
>                 > with Xerces 1.4 deployed on Weblogic, it always validates
> against the first
>                 > item in the <choice>.
>
>                 > Can anyone see any problems in my schema design?
>
>                 Yes. I think XML Spy is wrong here because you the model you
> have created is
>                 ambigous. The parser won't know which of the elementA
> elements it's parsing. I
>                 think this also violates the constraint the in the same
> model group you can't
>                 have two element declarations with the same name but
> different types.
>
>                 Unfortunately W3C XML Schema isn't very good at defining
> co-occurence
>                 constraints like this but RELAX-NG and Schematron can do
> this or you can choose
>                 to embedd some Schematron rules within your XML Schema to
> enforce the extra
>                 constraints. See [1] for an example of how a Schematron rule
> can be embedded
>                 within a W3C XML Schema.
>
>                 Cheers,
>                 /Eddie
>
>                 [1]
> http://lists.w3.org/Archives/Public/xmlschema-dev/2001Nov/0049.html
>
>                 >
>                 >
>                 > Thanks a lot,
>                 >
>                 > Sean
>                 >
>                 > <?xml version="1.0" encoding="UTF-8"?>
>                 > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
>                 > elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>                 >         <xs:attributeGroup name="AttGroupA">
>                 >                 <xs:attribute name="AA">
>                 >                         <xs:simpleType>
>                 >                                 <xs:restriction
> base="xs:string">
>                 >                                         <xs:minLength
> value="1"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >                 <xs:attribute name="BB">
>                 >                         <xs:simpleType>
>                 >                                 <xs:restriction
> base="xs:string">
>                 >                                         <xs:minLength
> value="1"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >         </xs:attributeGroup>
>                 >         <xs:attributeGroup name="AttGroupB">
>                 >                 <xs:attribute name="CC">
>                 >                         <xs:simpleType name="">
>                 >                                 <xs:restriction
> base="xs:string">
>                 >                                         <xs:maxLength
> value="40"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >                 <xs:attribute name="DD">
>                 >                         <xs:simpleType name="">
>                 >                                 <xs:restriction
> base="xs:string">
>                 >                                         <xs:minLength
> value="1"/>
>                 >                                         <xs:maxLength
> value="40"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >         </xs:attributeGroup>
>                 >         <xs:attributeGroup name="AttGroupC">
>                 >                 <xs:attribute name="CC">
>                 >                         <xs:simpleType name="">
>                 >                                 <xs:restriction
> base="xs:string">
>                 >                                         <xs:minLength
> value="1"/>
>                 >                                         <xs:maxLength
> value="40"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >                 <xs:attribute name="DD">
>                 >                         <xs:simpleType name="">
>                 >                                 <xs:restriction
> base="xs:string">
>                 >
>                 >                                         <xs:maxLength
> value="40"/>
>                 >                                 </xs:restriction>
>                 >                         </xs:simpleType>
>                 >                 </xs:attribute>
>                 >         </xs:attributeGroup>
>                 >         <xs:group name="ElementGroupA">
>                 >                 <xs:sequence>
>                 >                         <xs:element name="ElementA">
>                 >                                 <xs:complexType name="">
>                 >
>                 >                                         <xs:attributeGroup
> ref="AttGroupA"/>
>                 >                                         <xs:attributeGroup
> ref="AttGroupB"/>
>                 >                                 </xs:complexType>
>                 >                         </xs:element>
>                 >                 </xs:sequence>
>                 >         </xs:group>
>                 >         <xs:group name="ElementGroupB">
>                 >                 <xs:sequence>
>                 >                         <xs:element name="ElementA">
>                 >                                 <xs:complexType name="">
>                 >
>                 >                                         <xs:attributeGroup
> ref="AttGroupA"/>
>                 >                                         <xs:attributeGroup
> ref="AttGroupC"/>
>                 >                                 </xs:complexType>
>                 >                         </xs:element>
>                 >                 </xs:sequence>
>                 >         </xs:group>
>                 >         <xs:element name="TEST">
>                 >                 <xs:complexType>
>                 >                         <xs:choice>
>                 >                                 <xs:group
> ref="ElementGroupA"/>
>                 >                                 <xs:group
> ref="ElementGroupB"/>
>                 >                         </xs:choice>
>                 >                 </xs:complexType>
>                 >         </xs:element>
>                 > </xs:schema>
>                 >
>                 > <?xml version="1.0" encoding="UTF-8"?>
>                 > <TEST
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>                 > xsi:noNamespaceSchemaLocation="D:\Test.xsd">
>                 >         <ElementA AA="A" BB="B" CC="" DD=""/>
>                 > </TEST>
>                 >
>                 >
> -----------------------------------------------------------------
>                 > The xml-dev list is sponsored by XML.org
> <http://www.xml.org>, an
>                 > initiative of OASIS <http://www.oasis-open.org>
>                 >
>                 > The list archives are at
> http://lists.xml.org/archives/xml-dev/
>                 >
>                 > To subscribe or unsubscribe from this list use the
> subscription
>                 > manager: <http://lists.xml.org/ob/adm.pl>
>
>
> -----------------------------------------------------------------
>                 The xml-dev list is sponsored by XML.org
> <http://www.xml.org>, an
>                 initiative of OASIS <http://www.oasis-open.org>
>
>                 The list archives are at
> http://lists.xml.org/archives/xml-dev/
>
>                 To subscribe or unsubscribe from this list use the
> subscription
>                 manager: <http://lists.xml.org/ob/adm.pl>





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS