You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by yr...@daimlerchrysler.com on 2003/01/09 20:13:50 UTC

Re: question on xml schema validation with xerces 2





I think u also need to set the following two features

parser.setFeature( "http://xml.org/sax/features/namespaces",true);
parser.setFeature(
"http://apache.org/xml/features/validation/schema",true);

Sincerely,
Yarram Aravind Reddy
WebACE
Tie/L:870-5968
OutsideLine:(248) 427-5968
Email:YR11@daimlerchrysler.com


                                                                                                                                       
                      "Kiran Bhumana"                                                                                                  
                      <kBhumana@SeeBeyo        To:       <xe...@xml.apache.org>                                                 
                      nd.com>                  cc:                                                                                     
                                               Subject:  question on xml schema validation with xerces 2                               
                      01/09/2003 02:15                                                                                                 
                      PM                                                                                                               
                      Please respond to                                                                                                
                      xerces-j-dev                                                                                                     
                                                                                                                                       
                                                                                                                                       




Please enlighten me on this xmlschema Validation using apache xercesimpl.





I want to validate an xml file based on xmlschema. I did the following, the
following Java class and the simple xml file.





import org.apache.xerces.parsers.SAXParser;


import org.xml.sax.Attributes;


import org.xml.sax.helpers.DefaultHandler;


import org.xml.sax.SAXParseException;


import org.xml.sax.SAXException;


import java.io.IOException;





//  A Simple SAX Application


//  Extends org.xml.sax.helpers.DefaultHandler


public class BasicSAX extends DefaultHandler {





            // Constructor


            public BasicSAX (String xmlFile) {


                        //  Create a Xerces DOM Parser


                        SAXParser parser = new SAXParser();





                        //  Set Content Handler


                        parser.setContentHandler (this);





                        //  Parse the Document


                        try {





                            parser.setFeature("
http://xml.org/sax/features/validation", true);


                            parser.parse(xmlFile);


                        } catch (SAXException e) {


                                    System.err.println (e);


                        } catch (IOException e) {


                                    System.err.println (e);


                        }


            }





            //  Start Element Event Handler


            public void startElement (String uri, String local,


                        String qName, Attributes atts)  {


                        System.out.println (local);


            }





            // Main Method


            public static void main (String[] args) {


                        BasicSAX basicSAX = new BasicSAX (args[0]);


            }


}





<?xml version="1.0"?>


<note xmlns="http://www.w3schools.com"


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


xsi:schemaLocation="http://www.w3schools.com note.xsd"><to>Tove</to>


<from>Jani</from>


<heading>Reminder</heading>


<body>Don't forget me this weekend!</body>


</note>





The following is the output. Did I understand the apache documentation
wrongly or is this a bug ?





C:\Kiran\test>java -cp c:\kiran\test\xercesImpl.jar;c:\kiran\test BasicSAX
note.xml


[Error] note.xml:2:6: Document is invalid: no grammar found.


[Error] note.xml:2:6: Document root element "note", must match DOCTYPE root
"null".


note


to


from


heading


body








Thankyou,


Kiran B.










---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org