• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URGENT - Setting feature for SAX Parser in Xerces.

 
Lakshmi Ramachandran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I am writing an application in Java for parsing an XML document against a schema using Xerces 1.4.1. I am giving a snippet of my code in which I have set some features.
---------------
XMLReader parser = (XMLReader)Class.forName(PARSER_NAME).newInstance();
parser.setContentHandler(checker);
parser.setErrorHandler(checker);
parser.setFeature( "http://xml.org/sax/features/validation", true);
parser.setFeature( "http://xml.org/sax/features/namespaces", true);
parser.setFeature( "http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/dynamic",true);
parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true);
--------------
PROBLEM AREA:
(1) First of all the following exception is thrown -
org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/features/validation
/schema-full-checking
at org.apache.xerces.framework.XMLParser.setFeature(XMLParser.java:1169)
at org.apache.xerces.parsers.SAXParser.setFeature(SAXParser.java:573)
at SchemaChecker.main(SchemaChecker.java:57)
(2) When I commented the line
parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true);
It says that parsing has been done successfully. But it doesn't as I specifically made mistakes in the XML and the parser could not find that.
Please help me out for parsing XML against Schema using Xerces.
Hope to get an immediate response.
Regards.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking at Xerces 1.3.1 - source code for XMLParser.java
in the org.apache.xerces.framework package. I find the following array of String:
/** Features recognized by this parser. */
private static final String RECOGNIZED_FEATURES[] = {
// SAX2 core
"http://xml.org/sax/features/validation",
"http://xml.org/sax/features/external-general-entities",
"http://xml.org/sax/features/external-parameter-entities",
"http://xml.org/sax/features/namespaces",
// Xerces
"http://apache.org/xml/features/validation/schema",
"http://apache.org/xml/features/validation/dynamic",
"http://apache.org/xml/features/validation/default-attribute-values",
"http://apache.org/xml/features/validation/validate-content-models",
"http://apache.org/xml/features/validation/validate-datatypes",
"http://apache.org/xml/features/validation/warn-on-duplicate-attdef",
"http://apache.org/xml/features/validation/warn-on-undeclared-elemdef",
"http://apache.org/xml/features/allow-java-encodings",
"http://apache.org/xml/features/continue-after-fatal-error",
"http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
"http://apache.org/xml/features/nonvalidating/load-external-dtd"
};
------
I suggest you look at the source code for your version and see if the "schema-full-checking" type is there.
Bill

------------------
author of:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic