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 Jo Vandermeeren <jo...@gmail.com> on 2008/09/10 17:05:50 UTC

schema_reference.4: Failed to read schema document

Hi there,

I am having the following issue when trying to validate an XML file
using an XSD schema.
This is the error message: "schema_reference.4: Failed to read schema
document 'C:Test Demo\4.2
testing\tmp\xsd-cache\cached_schema_64465.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>."

I am creating the SAX parser as follows:
            SAXParserFactory factory =
javax.xml.parsers.SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);

            SAXParser parser = factory.newSAXParser();
            parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
            parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
resolveSchemaSource(schemaSource));

The resolveSchemaSource(String) method extracts the schema from the
classpath, copies it to a temporary location on disk and returns the
canonical path of the schema file.

Are there any other invalid characters that could end up in the path
that should be taken into account?

Thanks
Jo

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: schema_reference.4: Failed to read schema document

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Jo,

If you're providing a string as the value of the schemaSource property it's
supposed to be a valid URI.

"C:Test Demo\4.2testing\tmp\xsd-cache\cached_schema_64465.xsd" isn't a
valid URI. With the '\' missing after the 'C:' it doesn't look like a valid
Windows file path either. You should either fix up the string to make it a
valid URI (e.g.
file:///C:/Test%20Demo/4.2testing/tmp/xsd-cache/cached_schema_64465.xsd) or
set a java.io.File as the value of schemaSource instead.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Jo Vandermeeren" <jo...@gmail.com> wrote on 09/10/2008 11:05:50
AM:

> Hi there,
>
> I am having the following issue when trying to validate an XML file
> using an XSD schema.
> This is the error message: "schema_reference.4: Failed to read schema
> document 'C:Test Demo\4.2
> testing\tmp\xsd-cache\cached_schema_64465.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>."
>
> I am creating the SAX parser as follows:
>             SAXParserFactory factory =
> javax.xml.parsers.SAXParserFactory.newInstance();
>             factory.setNamespaceAware(true);
>             factory.setValidating(true);
>
>             SAXParser parser = factory.newSAXParser();
>             parser.setProperty("http://java.sun.
> com/xml/jaxp/properties/schemaLanguage",
> "http://www.w3.org/2001/XMLSchema");
>             parser.setProperty("http://java.sun.
> com/xml/jaxp/properties/schemaSource",
> resolveSchemaSource(schemaSource));
>
> The resolveSchemaSource(String) method extracts the schema from the
> classpath, copies it to a temporary location on disk and returns the
> canonical path of the schema file.
>
> Are there any other invalid characters that could end up in the path
> that should be taken into account?
>
> Thanks
> Jo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org