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

Re: XML Schema validation

From: Prakash Bande <prakash.bande@sdrc.com>
Date: Fri, 05 Oct 2001 10:21:47 +0530
Message-ID: <3BBD3C62.939CD624@sdrc.com>
To: "Hanumaiahgari, Srinivas" <Srinivas.Hanumaiahgari@dva.gov.au>, Xml News <xmlschema-dev@w3.org>
Hi,
Try using SAX2XMLReader parser object supplied with xerces-c (you may download
the latest available on apache's site). You can see how to set the features in
the SAX2Count example in the samples they have provided. By the way I am using
the parsers implemented in C++ and not Java.

I could not validate you doc with DOMParser or SAXParser (really didn't probe
much)

Regards,
Prakash.

"Hanumaiahgari, Srinivas" wrote:

> hi prakash,
> i got a schema validated acc to w3c. I am using xerces 1.4.3 - SAX. I did
> use all the features but somehow it doesnt validate my xml against schema.
>
> xml schema:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema"
>             elementFormDefault="qualified">
>
> xml doc:
>
> <?xml version='1.0' encoding='utf-8'?>
>
> <SupplierInvoice
>   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
>   xsi:noNameSpaceSchemaLocation='C:\binusha\ibmSchema.xsd'>
>
> Parser features:
>
>     parser.setFeature <file://parser.setFeature> ( "
> http://xml.org/sax/features/validation"
> <http://xml.org/sax/features/validation> , true);
>
> parser.setFeature("http://apache.org/xml/features/validation/schema",true);
>
> parser.setFeature("http://apache.org/xml/features/validation/schema-full-che
> cking",true);
>
> do i need to do anything else......plz put me in the right path.
>
> thanx,
> Srinivas Reddy H
>
> -----Original Message-----
> From: Prakash Bande [mailto:prakash.bande@sdrc.com]
> Sent: Thursday, 4 October 2001 15:38
> To: NJayaraman@tomax.com; Xml News
> Subject: Re: XML Schema validation
>
> 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
> <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
> <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
> <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   <mailto:Prakash.Bande@sdrc.com> Prakash.Bande@sdrc.com
>
> Ext.124,Ph.+91-2139-33666
>
> Structural Dynamics Research Corporation
>
> Product Groups - India
>

--

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

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