You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Pr...@alcatel.co.in on 2004/03/02 08:09:12 UTC
Failed to read Schema
I am new to xerces-J(version 2.x). I am experiencing problem with
specifying schema location(without namespace):
Here is the file sxcerpts:
sampleSchema.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- and so on -->
Sample.xml:
<?xml version = "1.0" encoding = "UTF-8"?>
<PropertySheet xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "schema/sampleSchema.xsd" Size = "SMALL">
<!-- and so on --->
Program Excerpts:
XMLReader reader=
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
//todo: Register Content Handlers
//todo: Register error Handler
//Parse
InputSource inputSource = new InputSource("xml/Sample.xml");
//inputSource.setSystemID(xmlURI);
//added
reader.setFeature("http://xml.org/sax/features/validation",
true);
reader.setFeature("http://apache.org/xml/features/validation/schema",
true);
reader.setFeature("http://xml.org/sax/features/namespaces",
true);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
false);
reader.setFeature("http://apache.org/xml/features/validation/dynamic",
true);
reader.parse(inputSource);
//and so on....
Running the program gives following error:
schema_reference.4: Failed to read schema document
'schema/PropertySheet.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
The directory structure is as below:
<project>/xml/Sample.xml
<project>/schema/sampleSchema.xsd
<project>/SAxParser.java
I have put <project> directory (and subdirectory) in a jar and specified
jar in the classpath.
Please note that if I move Sample.xml to <project> directory (from
<project>/xml), the parser *does not* gives any error.
I would appreciate if someone please help me how to specify schema location
independent of xml file location. The schema should be located in the
classpath instead.
TIA,
Prabhat
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org