Re: XML Schema validation

Hi Srinivas,
You made a small error writing the document. As per your schema the content of
DEPTNO element is an enum either 10, 20 or 30, and that of the DNAME is a
string with max length of 50 and containing only alphabets (both capital and
small). So your instance document should be like this:

<?xml version="1.0" encoding="UTF-8"?>
<DEPT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="kum.xsd">
<!-- DEPT File @ThatOne company -->
        <DEPTNO>10</DEPTNO>
        <DNAME>ABC</DNAME>
        <LOC>HAYWARD</LOC>
</DEPT>

Also in your schema change nullable to nillable. I am quoting below a mail from
a w3 mailing list:

From: "Jacqui Coosner" <jjc@incusdata.com>
To: <www-xml-schema-comments@w3.org>
Sent: Saturday, July 07, 2001 2:00 PM
Subject: Nillable or nullable?


> I notice that the new Schema Recommendation uses
> the term "nillable" as an attribute for use on elements
> which are permitted not to have comment. In the
> previous Candidate Recommendation dated 24 Oct 2000,
> the term used was "nullable" - which is what the tool I
> use currently supports.
> Is the new term a conscious change from the earlier
> one, or was one of them a typo?


Making these changes worked for me.

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 02:05:50 UTC