Main Page | Packages | Class Hierarchy | Class List | File List | Class Members

xmlexpr.ParserFactory Class Reference

List of all members.

Detailed Description

ParserFactory Jul 26, 2004.

Author:
Ian Kaplan, www.bearcave.com, iank@bearcave.com


Static Public Member Functions

DOMParser newParser (boolean validate)
 Allocate and initialize a new DOM parser.

Static Package Attributes

final String NAMESPACES_FEATURE_PREFIX = "http://xml.org/sax/features/namespaces"
 the namespace feature is true by default
final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation"
final String VALIDATION_SCHEMA_FEATURE = "http://apache.org/xml/features/validation/schema"

Static Private Member Functions

void setFeature (DOMParser parser, String featureURI, String featureName)
 Set a feature in the parser and report any errors.
void initParser (DOMParser parser, boolean validate)
 Turn on validation in the parser object.


Member Function Documentation

void xmlexpr.ParserFactory.initParser DOMParser  parser,
boolean  validate
[static, private]
 

Turn on validation in the parser object.

The W3C (www.w3.org) and Apache (www.apache.org) documentation is less than clear when it comes to XML Schemas and XML parsers. Initializing a parser so that it performs validation is rather obscure. The features that are set in initialization are URI strings. These are defined on the Apache web page:

        http://xml.apache.org/xerces2-j/features.html 

A parser feature is turned on by calling the parser method setFeature( featureStr, true ), where featureStr is one of the features defined on the Apache web page. The feature to turn on schema validation is:

        http://apache.org/xml/features/validation/schema

Error reporting requries that the basic validation feature be turned on as well. This is:

	    http://xml.org/sax/features/validation

Note that one feature uses apache.org and the other uses xml.org. Apparently this is historical: the base validation feature was originally for DTDs. The validation/schema feature is for XML Schema Descriptions (XSDs).

Parameters:
parser the parser object
validate true = turn validation on, false = no validation.
00120 { 00121 // parser.setErrorHandler(new DefaultHandler()); 00122 parser.setErrorHandler(new LocalErrorHandler() ); 00123 00124 if (validate) { 00125 setFeature( parser, VALIDATION_FEATURE, "VALIDATION_FEATURE" ); 00126 setFeature( parser, VALIDATION_SCHEMA_FEATURE, "VALIDATION_SCHEMA_FEATURE" ); 00127 } 00128 } // initParser

DOMParser xmlexpr.ParserFactory.newParser boolean  validate  )  [static]
 

Allocate and initialize a new DOM parser.

Parameters:
validate false = no validation, true = initialize the parser for XML schema validation
00139 { 00140 DOMParser parser = new DOMParser(); 00141 initParser( parser, validate ); 00142 return parser; 00143 } // newParser

void xmlexpr.ParserFactory.setFeature DOMParser  parser,
String  featureURI,
String  featureName
[static, private]
 

Set a feature in the parser and report any errors.

00071 { 00072 try { 00073 parser.setFeature(featureURI, true); 00074 } catch (SAXNotSupportedException e) { 00075 System.out.println("ParserFactory::initParser: " + featureName + 00076 " not supported by parser"); 00077 } catch (SAXNotRecognizedException e) { 00078 System.out.println("ParserFactory::initParser: " + featureName + 00079 " not recognized by parser"); 00080 } 00081 } // setFeature


Member Data Documentation

final String xmlexpr.ParserFactory.NAMESPACES_FEATURE_PREFIX = "http://xml.org/sax/features/namespaces" [static, package]
 

the namespace feature is true by default

final String xmlexpr.ParserFactory.VALIDATION_FEATURE = "http://xml.org/sax/features/validation" [static, package]
 

final String xmlexpr.ParserFactory.VALIDATION_SCHEMA_FEATURE = "http://apache.org/xml/features/validation/schema" [static, package]
 


The documentation for this class was generated from the following file:
Generated on Sat Aug 28 13:09:43 2004 for XmlExpr by doxygen 1.3.8