Hi,

 

I’m relatively new to Java, and am just starting to use XML parsing/validating within Java for the first time.  I’m finding the whole JavaX interface / Xerces class relationship confusing, and would really appreciate some guidance.

My question is, when I implement the code (shown below) with XercesImpl.Jar in my classpath, am I using the Xerces SAXParser (from the .jar) or am I using SAXParser supplied in the JDK?
I thought I had my head around this until I found the JDK is supplied with a version of Xerces, so now I’m confused whether my code is running the JDK version, or the latest version given in the classpath.

 

Apologies for the dumb question, but it’s confusing the life out of me.  If anyone can guide me it would be much appreciated.
Also, If anyone can point me to a good reference resource (website or book) I’d be grateful.

 

Regards,

 

Nigel.

 

 

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import org.xml.sax.SAXParseException;

import org.xml.sax.helpers.DefaultHandler;

 

public class XMLChecker3 extends DefaultHandler {

                private boolean documentIsValid = true;

                private boolean documentHadWarnings = false;

 

                public void parseURI(String uri) {

                                try {

                                                SAXParserFactory spf = SAXParserFactory.newInstance();

                                                spf.setNamespaceAware(true);

                                                spf.setValidating(true);

                                                SAXParser sp = spf.newSAXParser();

                                                sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",

                                                                                                   "http://www.w3.org/2001/XMLSchema");

                                                sp.parse(uri, this);

                                                if (documentIsValid) System.out.println("\nYour document is valid!");

                                                else if (documentHadWarnings) System.out.println("\nYour document had minor errors (warnings).");

                                                else System.out.println("\nYour document is not valid.");

                                } catch (Exception e) {

                                                System.err.println(e);

                                }

                }

 

                ….. exception handling methods ignored.

 

                /** Main program entry point. */

                public static void main(String argv[]) {

                                XMLChecker3 validator = new XMLChecker3();

                                validator.parseURI(argv[0]);

                }

}

Reply via email to