HI!

I am trying to provide a schema for a node, not for the whole document. 

Xerces 2.4.0 does not report a schema error in this case.

Example:

book.xsd:
<xs:schema targetNamespace="bookns" xmlns:a="bookns" 
xmlns:xs="http://www.w3.org/2001/XMLSchema";>

        <xs:element name="book">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="a:title"/>
                                <xs:element ref="a:author"/>
                                <xs:element ref="a:publisher"/>
                                <xs:element ref="a:isbn"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>

        <xs:element name="title" type="xs:string"/>
        <xs:element name="author" type="xs:string"/>
        <xs:element name="publisher" type="xs:string"/>
        <xs:element name="isbn" type="xs:string"/>
</xs:schema>


magazine.xsd:
<xs:schema targetNamespace="magazinens" xmlns:a="magazinens" 
xmlns:xs="http://www.w3.org/2001/XMLSchema";>

        <xs:element name="magazine">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="a:title"/>
                                <xs:element ref="a:publisher"/>
                                <xs:element ref="a:version"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>

        <xs:element name="title" type="xs:string"/>
        <xs:element name="publisher" type="xs:string" />
        <xs:element name="version" type="xs:string"/>
</xs:schema>


inventory01.xml:
<inventory>
      <m:magazine xmlns:m="magazinens" xsi:schemaLocation="magazinens 
magazine.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                <m:title>Core XML</m:title>
                <m:publisher>XC</m:publisher>
                <m:version>2003/11</m:version>
        </m:magazine>
        <b:book xmlns:b="bookns" xsi:schemaLocation="bookns book.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                <b:title_>XSD</b:title_>
                <b:author>Xaver Samuel Digit</b:author>
                <b:publisher>AW</b:publisher>
                <b:isbn>3-930673-62-2</b:isbn>
        </b:book>
      <m:magazine xmlns:m="magazinens" xsi:schemaLocation="magazinens 
magazine.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                <m:title_>Core XML</m:title_>
                <m:publisher>XC</m:publisher>
                <m:version>2003/11</m:version>
        </m:magazine>
</inventory>


Code:
    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    Document d;
    
    dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(true); 
    dbf.setAttribute("http://apache.org/xml/features/validation/dynamic";,
                    new Boolean(true));
    dbf.setAttribute("http://apache.org/xml/features/validation/schema";, 
                     new Boolean(true));
    
    db = dbf.newDocumentBuilder();
    db.setErrorHandler(new XMLDocument.XmlErrorHandler());
    d = db.parse(new File("C:\\inventory01.xml"));


This should throw an exception because of "title_".

Any ideas?


Thanks!

Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to