aspose file tools*
The moose likes XML and Related Technologies and the fly likes URGENT - Setting feature for SAX Parser in Xerces. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "URGENT - Setting feature for SAX Parser in Xerces." Watch "URGENT - Setting feature for SAX Parser in Xerces." New topic
Author

URGENT - Setting feature for SAX Parser in Xerces.

Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
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

Joined: Mar 22, 2000
Posts: 12825
    
    5
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URGENT - Setting feature for SAX Parser in Xerces.