W3C home > Mailing lists > Public > xmlschema-dev@w3.org > October 2001

Re: XML Schema validation

From: Prakash Bande <prakash.bande@sdrc.com>
Date: Thu, 04 Oct 2001 10:08:16 +0530
Message-ID: <3BBBE7B8.8568A79C@sdrc.com>
To: NJayaraman@tomax.com, Xml News <xmlschema-dev@w3.org>
Hi,
The document won't validate because your schema doesn't specify
dept_no_wrong_tag element in xml_root. It should rather be dept_no element (as
the schema says) in you document.
Your document should look like this.

<?xml version="1.0"?>
<xml_root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="simple_test.xsd">
     <dept>
          <dept_no>30000</dept_no>
          <description>Test Dept</description>
     </dept>
</xml_root>

This will validate.
Regards,
Prakash.

NJayaraman@tomax.com wrote:

> Hi,
>      I am trying to validate a xml using the following code, but it doesn't
> seem to validate. After getting the DOM tree I could always traverse the
> tree. Please let me know if I am missing something here to validate this.
> Thanks !!
>
> org.apache.xerces.parsers.DOMParser parser = new
> org.apache.xerces.parsers.DOMParser();
> parser.setErrorHandler(new tomax.utils.ValidXMLErrorHandler());
> try {
>    parser.parse(new InputSource(new FileInputStream("product_codes.xml")));
> //I expect Parser to throw error here
>    newXsdTest.xmlDoc = newXsdTest.getXMLDOM();
>    //....
>    //...
> }
> // ....
>
> Sample xml
>
> <?xml version="1.0"?>
> <xml_root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="simple_test.xsd">
>      <dept>
>           <dept_no_wrong_tag>30000</dept_no_wrong_tag>
>           <description>Test Dept</description>
>      </dept>
> </xml_root>
>
> Xml Schema
>
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="xml_root">
>   <xsd:complexType>
>     <xsd:sequence>
>      <xsd:element name="dept" minOccurs="0" maxOccurs="unbounded">
>         <xsd:complexType>
>         <xsd:sequence>
>           <xsd:element name="dept_no" type="xsd:integer"/>
>           <xsd:element name="description" type="xsd:string"/>
>         </xsd:sequence>
>          </xsd:complexType>
>       </xsd:element>
>     </xsd:sequence>
>    </xsd:complexType>
> </xsd:element>
> </xsd:schema>

--

Prakash Reddy Bande
email Prakash.Bande@sdrc.com
Ext.124,Ph.+91-2139-33666
Structural Dynamics Research Corporation
Product Groups - India
Received on Thursday, 4 October 2001 00:50:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:24 GMT