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 "Amthauer, Heiner" <He...@t-systems.com> on 2002/10/07 12:04:33 UTC

Not an FAQ: still unable to validate against XSD

Hi there!

I'm still unable to validate my xml file against an XSD. Here ist the code,
I use to load the file via SAX, using XERCES 2.0 (JRE1.3.1):

    private static final String FLAG_VALIDATE =
"http://xml.org/sax/features/validation";
    private static final String FLAG_SCHEMA =
"http://apache.org/xml/features/validation/schema";
    
    private SAXParserFactory factory = null;
    private org.xml.sax.SAXParser saxParser = null;

	...    
        factory = SAXParserFactory.newInstance();
	...
        saxParser = factory.newSAXParser();
	...
	saxParser.getXMLReader().setFeature(FLAG_VALIDATE, true);
	saxParser.getXMLReader().setFeature(FLAG_SCHEMA, true);
	saxParser.parse(new File(file), this);
	...

This always gives me an error saying "cvc-elt.1: Cannot find the declaration
of element 'whatever'".

Since then, I've tried to use an EntityResolver for loading the XSD. I've
started with writing a little test code for the EntryResolver like this:

public class SAXEntityResolver implements EntityResolver {

        public InputSource resolveEntity(String publicID, String systemID)
throws SAXException, IOException {
            System.out.println(publicID+", "+systemID);
            return null;
        }
        
}

...
    
    private static final String FLAG_VALIDATE =
"http://xml.org/sax/features/validation";
    private static final String FLAG_SCHEMA =
"http://apache.org/xml/features/validation/schema";
    
    private SAXParserFactory factory = null;
    private SAXParser saxParser = null;

	...    
        factory = SAXParserFactory.newInstance();
	...
        saxParser = factory.newSAXParser();
	...
	saxParser.getXMLReader().setFeature(FLAG_VALIDATE, true);
	saxParser.getXMLReader().setFeature(FLAG_SCHEMA, true);
	saxParser.getXMLReader().setEntityResolver(new SAXEntityResolver());
	saxParser.parse(new File(file), this);
	...

In result, my programm still reads the xml file with the same error as
before. The println() in the EntityResolver is never reached. 

I woulde really appreciate any help on this. Next on schedule is testing and
I'm still unable to validate the xml file. Btw., loading the file with any
other XML/XSD aware application works fine.

regards
Heiner


---------------------------------------------------------------
Dipl. Ing. Heiner Amthauer

T-Systems GEI GmbH

Hausanschrift: Magirusstr. 39/1, 89077 Ulm
Postanschrift: Postfach 20 64, 89010 Ulm
Telefon: +49 ( 731) 9344-4422
Telefax: +49 (731) 9344-4409
Mobil: +49 (1 78) 4269335
E-Mail: heiner.amthauer@t-systems.com
Internet: http://www.t-systems.com



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