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

saxparse.ParseMessage Class Reference

List of all members.

Detailed Description

ParseMessage Aug 9, 2004.

This object provides the parse method which builds a SAX parser and processes an XML document.

If the validate argument is true, the parser will be initialized for XML schema validation. The parser is also initialized to be namespace "aware" (e.g., it will support XML name spaces). Note that the namespace feature must be turned on for SAX parsers, but it is on by default for DOM parsers.

Initializing an XML 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

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


Public Member Functions

void parse (InputStream in, DefaultHandler handler, boolean validate) throws SAXException

Static Package Attributes

final String NAMESPACES_FEATURE_PREFIX = "http://xml.org/sax/features/namespaces"
final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation"
final String VALIDATION_SCHEMA_FEATURE = "http://apache.org/xml/features/validation/schema"

Private Member Functions

SAXParser newParser (boolean validate)

Static Private Member Functions

void setFeature (SAXParserFactory factory, String featureURI, String featureName)
 Set a feature in the parser and report any errors.
void initFactory (SAXParserFactory factory, boolean validate)


Member Function Documentation

void saxparse.ParseMessage.initFactory SAXParserFactory  factory,
boolean  validate
[static, private]
 

00096 { 00097 if (validate) { 00098 setFeature( factory, NAMESPACES_FEATURE_PREFIX, "NAMESPACE_FEATURE"); 00099 setFeature( factory, VALIDATION_FEATURE, "VALIDATION_FEATURE" ); 00100 setFeature( factory, VALIDATION_SCHEMA_FEATURE, "VALIDATION_SCHEMA_FEATURE" ); 00101 } 00102 } // initParser

SAXParser saxparse.ParseMessage.newParser boolean  validate  )  [private]
 

00106 { 00107 SAXParserFactory factory = SAXParserFactory.newInstance(); 00108 initFactory( factory, validate ); 00109 SAXParser parser = null; 00110 try { 00111 parser = factory.newSAXParser(); 00112 } catch (ParserConfigurationException e) { 00113 System.out.println("ParseMessage::newParser: ParserConfigurationException = " + e ); 00114 } catch (SAXException e) { 00115 System.out.println("ParseMessage::newParser: SAXException = " + e ); 00116 } 00117 return parser; 00118 }

void saxparse.ParseMessage.parse InputStream  in,
DefaultHandler  handler,
boolean  validate
throws SAXException
 

00123 { 00124 SAXParser parser = newParser(validate); 00125 try { 00126 parser.parse( in, handler ); 00127 } catch (IOException e) { 00128 System.out.println("ParseMessage::parse: IOException = " + e ); 00129 } 00130 }

void saxparse.ParseMessage.setFeature SAXParserFactory  factory,
String  featureURI,
String  featureName
[static, private]
 

Set a feature in the parser and report any errors.

00079 { 00080 try { 00081 factory.setFeature(featureURI, true); 00082 } catch (SAXNotSupportedException e) { 00083 System.out.println("ParseMessage::setFeature: " + featureName + 00084 " not supported by parser"); 00085 } catch (SAXNotRecognizedException e) { 00086 System.out.println("ParseMessage::setFeature: " + featureName + 00087 " not recognized by parser"); 00088 } 00089 catch (ParserConfigurationException e) { 00090 System.out.println("ParseMessage::setFeature: " + e); 00091 } 00092 } // setFeature


Member Data Documentation

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

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

final String saxparse.ParseMessage.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:50:04 2004 for SaxParse by doxygen 1.3.8