RE: How to use DTD and Schema in the single XML file?

This is one reason I proposed a flatter schema than the one you quote.

At one stage the XSLT/XQuery specs had a mechanism for referencing
non-global element or type definitions, but we decided to take it out,
partly because it was very poorly specified and difficult to fix (for
example, it wasn't clear how named groups affected things), and partly
because it was felt that an addressing mechanism for non-global components
ought to come from the Schema WG itself.

For the moment, in XSLT you can validate against a global element definition
or a global type. In XQuery you can only validate against a global element
definition. (I added validation against a global type as an extension in
Saxon XQuery because one of my users was heavily using FpML, which IIRC has
only one global element definition but lots of global types).

Saxon will allow you to validate against a non-global type using the Java
API, but you'll have to grovel around the Javadoc to work out how to do it.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Philippe Poulard [mailto:Philippe.Poulard@sophia.inria.fr] 
> Sent: 26 July 2006 14:47
> To: Michael Kay
> Cc: 'Balakrishnan'; 'Mukul Gandhi'; xmlschema-dev@w3c.org
> Subject: Re: How to use DTD and Schema in the single XML file?
> 
> Michael Kay wrote:
> > 
> > There are not many tools that offer selective validation at the 
> > element level, but you can do it with a schema-aware XQuery 
> or XSLT 2.0 stylesheet:
> > 
> > <xsl:template match="element-to-be-validated">
> >   <xsl:copy-of select="." validation="strict"/> </xsl:template>
> > 
> > Michael Kay
> > http://www.saxonica.com/
> > 
> > 
> 
> hi,
> 
> according to this piece of spec :
> http://www.w3.org/TR/xslt20/#validation
> "The [xsl:]validation attribute is used to request validation 
> against the global element or attribute declaration whose 
> name matches the name of the element or attribute being validated."
> 
> ...if I had a schema like this :
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema version="1.0"
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>    <xsd:element name="root" type="rootType" />
>    <xsd:complexType name="rootType">
>      <xsd:sequence>
>        <xsd:element name="product" maxOccurs="unbounded">
>          <xsd:complexType>
>            <xsd:sequence>
>                  <xsd:element name="name" type="xsd:string"/>
>                  <xsd:element name="url">
>                    <xsd:complexType>
>                      <xsd:sequence>
>                          <xsd:element name="product" 
> type="xsd:string"/>
>                          <xsd:element name="image" type="xsd:string"/>
>                      </xsd:sequence>
>                    </xsd:complexType>
>                  </xsd:element>
>            </xsd:sequence>
>          </xsd:complexType>
>        </xsd:element>
>      </xsd:sequence>
>    </xsd:complexType>
> </xsd:schema>
> 
> ...that validates this document :
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>   <product>
>     <name>Product name</name>
>     <url>
>       <product>http://product.url.com</product>
>       <image>http://product.image.com</image>
>     </url>
>   </product>
>   <product>
>     <name>Product name 2</name>
>     <url>
>       <product>http://product.url.com</product>
>       <image>http://product.image.com</image>
>     </url>
>   </product>
> </root>
> 
> ...would it be possible to validate the "product" element ?
> 
> <xsl:template match="product">
>    <xsl:copy-of select="." validation="strict"/> </xsl:template>
> 
> if I understood the story, there is no "global element 
> declaration" for <product>
> 
> more generally, is there a tool (in Java ?) that can validate 
> an arbitrary element against a schema where element 
> declarations are written à la russian-doll ?
> 
> is there a way to achieve this anyway without trying to 
> validate the parent element (and perhaps its ancestors) in 
> order to retrieve the definition ? I think about some 
> conversion to an XPath pattern (or another kind of selector), 
> that would be bound to each definition and that could be 
> tested on the candidate element (all the definitions for a 
> given element would be retrievable in a single set) ?
> 
> mmmh, I wonder if there is not such a flattening mechanism in 
> Relax NG that allows to retrieve the definition(s) of an element
> 
> --
> Cordialement,
> 
>                ///
>               (. .)
>   --------ooO--(_)--Ooo--------
> |      Philippe Poulard       |
>   -----------------------------
>   http://reflex.gforge.inria.fr/
>         Have the RefleX !

Received on Wednesday, 26 July 2006 14:36:55 UTC