|
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. |
