On 4 Nov, 2005, at 11:06 am, Nigel Kibble wrote:

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.


Hi Nigel,

As you've noted, Java 1.4 comes with a copy of Xerces. Unfortunately, Sun left the package structure unchanged, so you run into trouble when trying to use a later version of Xerces than that supplied with the JRE. By default, the JRE classes will be used in preference to those in the classpath. The simplest way to get Java to use your copy of Xerces instead of its own is to use the java.endorsed.dirs system property:

http://java.sun.com/j2se/1.4.2/docs/guide/standards/

Hope this helps.

Mark.

 
 
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]);
                }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to