com.calitha.xml
Class SimpleDOMParser

java.lang.Object
  extended by com.calitha.xml.SimpleDOMParser

public class SimpleDOMParser
extends Object

The SimpleDOMParser class represent an XML parser with a simplified API.

You can pass a configuration to the constructor to get the desired features for example for validation. Take a look at the IParserConfiguration and its implementations for the kind of configurations you can use.

Author:
Robert van Loenhout

Constructor Summary
SimpleDOMParser()
          Creates a new SimpleDOMParser.
SimpleDOMParser(IParserConfiguration configuration)
          Creates a new SimpleDOMParser.
 
Method Summary
 Document getDocument()
          The DOM parsed from XML input.
 boolean getDynamicValidationFeature()
          Determines if the dynamic validation feature is enabled.
 EntityResolver getEntityResolver()
          Gets the custom handler for external entities.
 SimpleErrorHandler getErrorHandler()
          Gets the error handler.
 org.apache.xerces.xni.grammars.XMLGrammarPool getGrammarPool()
          Gets the grammar pool.
 boolean getNamespacesFeature()
          Determines if the namespaces feature is enabled.
 String getNoNamespaceSchemaLocation()
          Gets the override schema location for no namespace.
 String getSchemaLocation()
          Gets the override schema location for namespaces.
 boolean getSchemaValidationFeature()
          Determines if the schema validation feature is enabled.
 boolean getValidationFeature()
          Determines if the validation feature is enabled.
 void parse(InputSource input)
          Parses the XML input.
 void parse(InputStream input)
          Parses the XML input.
 void setDynamicValidationFeature(boolean value)
          Sets the dynamic validation feature.
 void setEntityResolver(EntityResolver entityResolver)
          Sets the custom handler for external entities.
 void setGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool pool)
          Sets the grammar pool.
 void setNamespacesFeature(boolean value)
          Sets the namespace feature.
 void setNoNamespaceSchemaLocation(String location)
          Sets the override schema location for no namespace.
 void setNoNamespaceSchemaLocation(URL location)
          Sets the override schema location for no namespace.
 void setSchemaLocation(String location)
          Sets the override schema location for namespaces.
 void setSchemaValidationFeature(boolean value)
          Sets the schema validation feature.
 void setValidationFeature(boolean value)
          Sets the validation feature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDOMParser

public SimpleDOMParser()
Creates a new SimpleDOMParser.

This parser has default settings supplied by the internal XML parser.


SimpleDOMParser

public SimpleDOMParser(IParserConfiguration configuration)
                throws SAXNotSupportedException,
                       SAXNotRecognizedException
Creates a new SimpleDOMParser. The specified configuration is used toe configure the parser.

Parameters:
configuration - configuration
Throws:
SAXNotSupportedException - if it recognizes a feature or property identifier, but cannot perform the requested operation
SAXNotRecognizedException - if it finds an unrecognized feature or property identifier
Method Detail

getNamespacesFeature

public boolean getNamespacesFeature()
Determines if the namespaces feature is enabled.

Returns:
true if enabled, otherwise false
See Also:
IParserConfiguration

setNamespacesFeature

public void setNamespacesFeature(boolean value)
Sets the namespace feature.

Parameters:
value - new feature value
See Also:
IParserConfiguration

getValidationFeature

public boolean getValidationFeature()
Determines if the validation feature is enabled.

Returns:
true if enabled, otherwise false
See Also:
IParserConfiguration

setValidationFeature

public void setValidationFeature(boolean value)
Sets the validation feature.

Parameters:
value - new feature value
See Also:
IParserConfiguration

getDynamicValidationFeature

public boolean getDynamicValidationFeature()
Determines if the dynamic validation feature is enabled.

Returns:
true if enabled, otherwise false
See Also:
IParserConfiguration

setDynamicValidationFeature

public void setDynamicValidationFeature(boolean value)
Sets the dynamic validation feature.

Parameters:
value - new feature value
See Also:
IParserConfiguration

getSchemaValidationFeature

public boolean getSchemaValidationFeature()
Determines if the schema validation feature is enabled.

Returns:
true if enabled, otherwise false
See Also:
IParserConfiguration

setSchemaValidationFeature

public void setSchemaValidationFeature(boolean value)
Sets the schema validation feature.

Parameters:
value - new feature value
See Also:
IParserConfiguration

getGrammarPool

public org.apache.xerces.xni.grammars.XMLGrammarPool getGrammarPool()
Gets the grammar pool.

The grammar pool can contain DTD's and Schema's for validation.

Returns:
grammar pool
See Also:
CachingValidatingConfiguration, PreParsedGrammarsConfiguration, XMLGrammarPoolBuilder

setGrammarPool

public void setGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool pool)
Sets the grammar pool.

The grammar pool can contain DTD's and Schema's for validation.

Parameters:
pool - grammar pool
See Also:
CachingValidatingConfiguration, PreParsedGrammarsConfiguration, XMLGrammarPoolBuilder

getSchemaLocation

public String getSchemaLocation()
Gets the override schema location for namespaces.

The location contains one or more pairs of namespace and XML Schema location. It overrides the location set in the XML file, so you can use schema's that are stored in a different location.

Returns:
schema location

setSchemaLocation

public void setSchemaLocation(String location)
Sets the override schema location for namespaces.

The location contains one or more pairs of namespace and XML Schema location. It overrides the location set in the XML file, so you can use schema's that are stored in a different location.

Parameters:
location - schema location
See Also:
SchemaLocationBuilder

getNoNamespaceSchemaLocation

public String getNoNamespaceSchemaLocation()
Gets the override schema location for no namespace.

The location contains one or more XML Schema location. It overrides the location set in the XML file, so you can use schema's that are stored in a different location.

Returns:
schema location

setNoNamespaceSchemaLocation

public void setNoNamespaceSchemaLocation(String location)
Sets the override schema location for no namespace.

The location contains one or more XML Schema location. It overrides the location set in the XML file, so you can use schema's that are stored in a different location.

Parameters:
location - schema location

setNoNamespaceSchemaLocation

public void setNoNamespaceSchemaLocation(URL location)
Sets the override schema location for no namespace.

The location contains one or more XML Schema location. It overrides the location set in the XML file, so you can use schema's that are stored in a different location.

Parameters:
location - schema location

getEntityResolver

public EntityResolver getEntityResolver()
Gets the custom handler for external entities.

Some configurations sets a special handler.

Returns:
entity resolver

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Sets the custom handler for external entities.

Some configurations sets a special handler.

Parameters:
entityResolver - entity resolver.

getErrorHandler

public SimpleErrorHandler getErrorHandler()
Gets the error handler.

The error handler contains warnings and errors from the last parse action.

Returns:
error handler

parse

public void parse(InputSource input)
           throws IOException,
                  SAXException
Parses the XML input.

Parameters:
input - XML input
Throws:
IOException - if an I/O error occurs
SAXException - if a XML parse error occurs
XMLValidateException - if a validation error occurs (SAXException subclass)

parse

public void parse(InputStream input)
           throws IOException,
                  SAXException
Parses the XML input.

Parameters:
input - XML input
Throws:
IOException - if an I/O error occurs
SAXException - if a XML parse error occurs
XMLValidateException - if a validation error occurs (SAXException subclass)

getDocument

public Document getDocument()
The DOM parsed from XML input.

This is available after a successful parse.

Returns:
DOM