|
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?
Apologies for the dumb question, but it’s confusing the life out
of me. If anyone can guide me it would be much appreciated.
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]); } } |
- Basic guidance Nigel Kibble
- Re: Basic guidance Mark Goodhand
- Re: Basic guidance Stanimir Stamenkov
- Re: Basic guidance Stanimir Stamenkov
- Re: Basic guidance Michael Glavassevich
- Re: Basic guidance Stanimir Stamenkov
- RE: Basic guidance Nigel Kibble
- RE: Basic guidance Nigel Kibble
