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 13:48:48 UTC