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

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xml-dev] tricky validation problem w multiple schemas



Hi Maomi,

> 1.    Neither XML Spy nor Topologi has a way for me to validate the
> > appropriate piece of XML instance doc 2 against FRIPQ "in situ."  That
> > is, the only way I've found to validate against FRIPQ.xsd is to snip out
> > that piece of XML and make it a separate instance doc.

I assume your talking about the Topologi Schematron Validator when you mention
Topologi above. I just tested your example (I think) using the following schemas
and instance:

instance:

<DO xsi:noNamespaceSchemaLocation="schemalocation_any.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
 <DS DSID="a">
  <MIME>text/plain</MIME>
 </DS>
 <DS DSID="b">
  <MIME>image/gif</MIME>
 </DS>
 <FRIP FID="f1">
  <desc>this is an instance of a Q frip</desc>
  <FSch:root xmlns:FSch="http://fsch.ns"; xsi:schemaLocation="http://fsch.ns
FRIPQ.xsd">
   <FSch:roleq1 RDSID="a" />
   <FSch:roleq2 RDSID="b" />
  </FSch:root>
 </FRIP>
</DO>

main_schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
 <xs:element name="DO">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="DS" minOccurs="1" maxOccurs="unbounded">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="MIME" type="xs:string"/>
      </xs:sequence>
      <xs:attribute name="DSID" use="required" type="xs:string"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="FRIP">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="desc" type="xs:string"/>
       <xs:any minOccurs="1" maxOccurs="unbounded" processContents="strict"/>
      </xs:sequence>
      <xs:attribute name="FID" type="xs:string" use="required"/>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

schema for http://fsch.ns namespace

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="http://fsch.ns"; xmlns:fsc="http://fsch.ns";>
 <xs:element name="root">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="roleq1">
     <xs:complexType>
      <xs:attribute name="RDSID" type="xs:string" use="required"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="roleq2">
     <xs:complexType>
      <xs:attribute name="RDSID" type="xs:string" use="required"/>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

If you run the above instance document with Topologi Schematron Validator it
will validate just fine (even the part declared as <xs:any> will be validated
against the http://fsch.ns namespace schema). The important thing you have to do
though is to turn on "DTD validation". Yes, I know it's a bad name to call the
switch that turns on validation but it's a hangover from the time when MSXML4
didn't support the xsi:schemaLocation attribute which meant only DTD Validation
was turned on and off. In the next version we should change this to "DTD/Schema
validation".

> >       d.  specific frip validating doc can validate:
> >               i.      correct role elements for specific frip
> >               ii.     attribute RDSID for each role is an IDREF
> > refering to a DSID in a DS element in DO instance doc.
> >               iii.    match RDSID for each role to DSID pertaining to
> > correct MIME type specified (e.g. for Frip Q, roleq1 must match DS with
> > MIME "text/plain")

Since your already using the Schematron Validator you can do this by embedding
Schematron rules within your XML Schema. For example, your last rule (iii) could
be expressed by embedding a Schematron rule on the <xs:any> declaration like
this:

       <xs:any minOccurs="1" maxOccurs="unbounded" processContents="strict"
namespace="http://fsch.ns";>
        <xs:annotation>
         <xs:appinfo>
          <sch:pattern name="FRIP Q"
xmlns:sch="http://www.ascc.net/xml/schematron";>
           <sch:rule context="DO/FRIP[@FID = 'f1']/FSch:root/FSch:roleq1">
<!-- This is assuming that FRIP Q is identifyed by @FID='f1'??? -->
            <sch:assert test="@RDSID = /DO/DS[MIME = 'text/plain']/@DSID">For
Frip Q, roleq1 must match DS with MIME "text/plain").</sch:assert>
           </sch:rule>
          </sch:pattern>
         </xs:appinfo>
        </xs:annotation>
       </xs:any>

You also need to define the namespace used for the components declared for
xs:any by adding the following <xs:annotation> to the top of your schema (first
child of the xs:schema element):

 <xs:annotation>
  <xs:appinfo>
   <!-- Declare the namespace for the elements in <xs:any> for use by Schematron
-->
   <sch:ns prefix="FSch" uri="http://fsch.ns";
xmlns:sch="http://www.ascc.net/xml/schematron"/>
  </xs:appinfo>
 </xs:annotation>

For more information about Schematron see [1].

Cheers,
/Eddie

[1] http://www.ascc.net/xml/resource/schematron/