I'm compiling the following code with xerces.jar in the CLASSPATH:
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Attribute;
import org.dom4j.io.SAXReader;
import org.dom4j.datatype.DatatypeDocumentFactory;
import java.io.*;
import java.util.*;
/**
* Parses the XML Schema in "po.xsd"
*/
public class XercesException {
public static void main (String[] args) {
SAXReader reader = new SAXReader(true);
Document doc = null;
reader.setDocumentFactory(DatatypeDocumentFactory.getInstance());
try {
doc = reader.read(new File("po.xsd"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
I'm using the file "po.xsd" given as an example of a XML schema at
http://www.w3.org/TR/xmlschema-0/#po.xsd
The first line of the file goes like this:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
When I execute the code, I get an exception (see end of post). The
schema in po.xsd checks out as correct with IBM's Schema Quality
Checker at
http://www.alphaworks.ibm.com/tech/xmlsqc
Can anyone explain why I get this exception? I've tried several
different versions of Xerces and all fail with similar exceptions.
My classpath contains the following jars:
xsdlib.jar:dom4j.jar:rt.jar:relaxngDatatype.jar:xerces.jar
Thanks,
David
EXCEPTION:
org.dom4j.DocumentException: Error on line 1 of document : General Schema Error: Gr\
ammar with uri 2: http://www.w3.org/2001/XMLSchema , can not found. Nested exception\
: General Schema Error: Grammar with uri 2: http://www.w3.org/2001/XMLSchema , can n\
ot found.
at org.dom4j.io.SAXReader.read(SAXReader.java:355)
at org.dom4j.io.SAXReader.read(SAXReader.java:219)
at XercesException.main(XercesException.java:24)
Nested exception: org.xml.sax.SAXParseException: General Schema Error: Grammar with \
uri 2: http://www.w3.org/2001/XMLSchema , can not found.
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1067)
at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLErro\
r(XMLValidator.java:1659)
at org.apache.xerces.validators.common.XMLValidator.validateElementAndAttrib\
utes(XMLValidator.java:3005)
at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLVali\
dator.java:1129)
at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentSca\
nner.java:1862)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch\
(XMLDocumentScanner.java:1005)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScann\
er.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at org.dom4j.io.SAXReader.read(SAXReader.java:219)
at XercesException.main(XercesException.java:24)