Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XSD Schema Location

843834Sep 5 2007 — edited Sep 7 2007
Hello all,

I have following example code:
package javaapplication4;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class Main implements ErrorHandler {

    public static void main(String[] args) {
        try {
            SAXReader reader = new SAXReader();
            
            reader.setValidation(true);
            
            reader.setFeature("http://xml.org/sax/features/validation", true);
            reader.setFeature("http://apache.org/xml/features/validation/schema", true );
            reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
            reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "C:\\schema.xsd");
 
            reader.setErrorHandler(new Main());
            
            Document document = reader.read("C:\\file.xml");
            
        } catch (DocumentException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        }
    }

    public void warning(SAXParseException exception) throws SAXException {
        throw exception;
    }

    public void error(SAXParseException exception) throws SAXException {
        throw exception;
    }

    public void fatalError(SAXParseException exception) throws SAXException {
        throw exception;
    }
}
Header in my xsd file ("C:\\schema.xsd") is:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
When I run above code I see following error:
org.dom4j.DocumentException: Error on line 4 of document file:///C:/schema.xsd : schema_reference.4: Failed to read schema document 'http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.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>. Nested exception: schema_reference.4: Failed to read schema document 'http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.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>.
        at org.dom4j.io.SAXReader.read(SAXReader.java:482)
        at org.dom4j.io.SAXReader.read(SAXReader.java:321)
        at javaapplication4.Main.main(Main.java:43)
Nested exception: 
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.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 think, that problem is in no internet connection in my computer, therefore file "http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd" is not reachable.
I place "xmldsig-core-schema.xsd" file in my "C:\" directory. How can I set this xsd location in my source (setFeature, setProperty ?)???

What should I do to eliminate this Error?

BTW, When I remove from my xsd file any "xmldsig" lines everything is OK.

Thanks for any help.

--
best regards,
zajjar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 5 2007
Added on Sep 5 2007
6 comments
5,306 views