org.apache.crimson.parser
Class ValidatingParser
java.lang.Object
org.apache.crimson.parser.Parser2
org.apache.crimson.parser.ValidatingParser
- public class ValidatingParser
- extends Parser2
This parser tests XML documents against the validity constraints
specified in the XML 1.0 specification as it parses them. It
reports violations of those constraints using the standard SAX API.
This parser should be configured to use an ErrorHandler
that reject documents with validity errors, otherwise they will be accepted
despite errors. The default error handling, as specified by SAX,
ignores all validity errors. The simplest way to have validity errors
have a useful effect is to pass a boolean true value to
the parser's constructor.
Note that most validity checks are performed during parsing by
the base class, for efficiency. They're disabled by default in
that class, and enabled by the constructor in this class.
- Author:
- David Brownell
Constructor Summary |
ValidatingParser()
Constructs a SAX parser object. |
ValidatingParser(boolean rejectValidityErrors)
Constructs a SAX parser object, optionally assigning the error
handler to report exceptions on recoverable errors (which include
all validity errors) as well as fatal errors. |
Methods inherited from class org.apache.crimson.parser.Parser2 |
chooseLocale, error, getLocale, isFastStandalone, parse, pushInputBuffer, setContentHandler, setDeclHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFastStandalone, setIsValidating, setLexicalHandler, setLocale, setNamespaceFeatures, setSecurityConstraintValues |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ids
private SimpleHashtable ids
EMPTY
private final ValidatingParser.EmptyValidator EMPTY
ValidatingParser
public ValidatingParser()
- Constructs a SAX parser object.
ValidatingParser
public ValidatingParser(boolean rejectValidityErrors)
- Constructs a SAX parser object, optionally assigning the error
handler to report exceptions on recoverable errors (which include
all validity errors) as well as fatal errors.
- Parameters:
rejectValidityErrors
- When true, the parser will use an
error handler which throws exceptions on recoverable errors.
Otherwise it uses the default SAX error handler, which ignores
such errors.
afterRoot
void afterRoot()
throws org.xml.sax.SAXException
- Overrides:
afterRoot
in class Parser2
- Throws:
org.xml.sax.SAXException
afterDocument
void afterDocument()
- Overrides:
afterDocument
in class Parser2
validateAttributeSyntax
void validateAttributeSyntax(AttributeDecl attr,
String value)
throws org.xml.sax.SAXException
- Description copied from class:
Parser2
- To validate, subclassers should at this time make sure that
values are of the declared types:
- ID and IDREF(S) values are Names
- NMTOKEN(S) are Nmtokens
- ENUMERATION values match one of the tokens
- NOTATION values match a notation name
- ENTITIY(IES) values match an unparsed external entity
Separately, make sure IDREF values match some ID
provided in the document (in the afterRoot method).
- Overrides:
validateAttributeSyntax
in class Parser2
- Throws:
org.xml.sax.SAXException
newContentModel
ContentModel newContentModel(String tag)
- Overrides:
newContentModel
in class Parser2
newContentModel
ContentModel newContentModel(char type,
ContentModel next)
- Overrides:
newContentModel
in class Parser2
newValidator
ElementValidator newValidator(ElementDecl element)
- Description copied from class:
Parser2
- To validate, subclassers should create an object that can
accept valid streams of element names, text, and terminate.
- Overrides:
newValidator
in class Parser2
isUnparsedEntity
private boolean isUnparsedEntity(String name)