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 Ashwin Desai <as...@yahoo.com> on 2004/02/02 23:22:07 UTC

XML Schema Validation problems

Hi,

I am using the xerces 2.6 parser to validate xml documents against
their schema. I have even set the correct features required for
schema checking (as in samples/sax/Counter.java). But, for some weird
reason, my xml documents are not getting validated. Also, the parser
does not complain about any features not being supported. 

JDK VERSION: java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

XERCES VERSION: xerces-2_6_0

I am enclosing the code where I set the features. I would appreciate
your help with this. 


/** Namespaces feature id (http://xml.org/sax/features/namespaces).
*/
    protected static final String NAMESPACES_FEATURE_ID =
"http://xml.org/sax/features/namespaces";

 /** Namespace prefixes feature id
(http://xml.org/sax/features/namespace-prefixes). */
    protected static final String NAMESPACE_PREFIXES_FEATURE_ID =
"http://xml.org/sax/features/namespace-prefixes";

/** Validation feature id (http://xml.org/sax/features/validation).
*/
    protected static final String VALIDATION_FEATURE_ID =
"http://xml.org/sax/features/validation";

/** Schema validation feature id
(http://apache.org/xml/features/validation/schema). */
    protected static final String SCHEMA_VALIDATION_FEATURE_ID =
"http://apache.org/xml/features/validation/schema";

/** Schema full checking feature id
(http://apache.org/xml/features/validation/schema-full-checking). */
    protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID =
"http://apache.org/xml/features/validation/schema-full-checking";

/** Dynamic validation feature id
(http://apache.org/xml/features/validation/dynamic). */
    protected static final String DYNAMIC_VALIDATION_FEATURE_ID =
"http://apache.org/xml/features/validation/dynamic";

 /** Default parser name. */
    protected static final String DEFAULT_PARSER_NAME =
"org.apache.xerces.parsers.SAXParser";

   /** Default namespaces support (true). */
    protected static final boolean DEFAULT_NAMESPACES = true;

    /** Default namespace prefixes (false). */
    protected static final boolean DEFAULT_NAMESPACE_PREFIXES =
false;

    /** Default validation support (false). */
    protected static final boolean DEFAULT_VALIDATION = true;

    /** Default Schema validation support (false). */
    protected static final boolean DEFAULT_SCHEMA_VALIDATION = true;

    /** Default Schema full checking support (false). */
    protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING =
true;

    /** Default dynamic validation support (false). */
    protected static final boolean DEFAULT_DYNAMIC_VALIDATION =
false;

   /**
     * Initializes the features and sets up the parser.
     *
     * @throws SAXException if the features cannot be set.
     */
    protected void initializeParser(XMLReader parser) throws
SAXException {
          // set parser features
            try {
                parser.setFeature(NAMESPACES_FEATURE_ID, namespaces);
            }
            catch (SAXException e) {
                System.err.println("warning: Parser does not support
feature ("+NAMESPACES_FEATURE_ID+")");
                throw e;
            }
            try {
                parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID,
namespacePrefixes);
            }
            catch (SAXException e) {
                System.err.println("warning: Parser does not support
feature ("+NAMESPACE_PREFIXES_FEATURE_ID+")");
                throw e;
            }
    try {
                parser.setFeature(VALIDATION_FEATURE_ID, validation);
            }
            catch (SAXException e) {
                System.err.println("warning: Parser does not support
feature ("+VALIDATION_FEATURE_ID+")");
                throw e;
            }
            try {
                parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID,
schemaValidation);
            }
            catch (SAXNotRecognizedException e) {
                System.err.println("warning: Parser does not support
feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
                throw e;
            }
            catch (SAXNotSupportedException e) {
                System.err.println("warning: Parser does not support
feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
                throw e;
            }
            try {
                parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID,
schemaFullChecking);
            }
            catch (SAXNotRecognizedException e) {
                System.err.println("warning: Parser does not support
feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
                throw e;
            }
            catch (SAXNotSupportedException e) {
                System.err.println("warning: Parser does not support
feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
                throw e;
            }

            try {
               parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID,
dynamicValidation);
            }
            catch (SAXNotRecognizedException e) {
                System.err.println("warning: Parser does not support
feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")");

            }
            catch (SAXNotSupportedException e) {
                System.err.println("warning: Parser does not support
feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")");
            }
}

void start()
{
      XMLReader xmlReader = XMLReaderFactory.createXMLReader
(DEFAULT_PARSER_NAME);
// Sets the features.
            initializeParser(xmlReader);
            BufferedReader fileReader = new BufferedReader (new
FileReader (new File (_fileName)));

            xmlReader.setContentHandler (this._handler);
            xmlReader.setErrorHandler (this._handler);

}

Thanks a lot,
Ashwin.









=====
Ashwin Desai.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

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