The XML DTD Parser API
Initial Parser
parses the input text, searches for parameter
entity declarations (i.e. entities used only within XML DTD)
and substitutes parameter entity
references by corresponding replacement text. All other
text is passed to the output "as is".<!ENTITY % name "John White" >signaling an error if an external parameter entity declaration, like:
<!ENTITY % ISOLat2 SYSTEM "http://www.xml.com/iso/isolat2-xml.entities" >is met. Future versions will be able to parse and handle external parameter entity declarations.
Main Parser
performes the main parsing process. It is able to parse:
<![ INCLUDE [ ... ]]> <![ IGNORE [ ... ]]>
<?xml version="1.0" encoding="UTF-16"?>
The parser is fully compliant with the current
XML specification,
unless otherwise is stated, for instance it is able to parse Unicode text,
provided the java.io.Reader
used to instantiate
the parser is correctly set up.
The structure of the package:
The parser was written using JavaCC (Java Compiler Compiler) - an automated tool to generate Java programming language parsers.
This package consists of the following classes and files:
DTDInitialParser
,
DTDInitialParserConstants
,
DTDInitialParserTokenManager
- classes of the initial parser automatically generated by JavaCC from
the DTDInitialParser.jj file.
DTDParser
,
DTDParserConstants
,
DTDParserTokenManager
- classes of the main parser automatically generated by JavaCC from
the DTDParser.jj file.
Token
,
ParseException
,
TokenMgrError
,
CharStream
-
classes used by both parsers and suitable for any grammar. JavaCC
first looks for these files and generates them only if they are absent.
But do not edit the first line of these files,
as JavaCC will give warning message about being unable to authenticate them.
TokenMgrError
is thrown if the Token Manager of the parser has encountered
a syntax error in the text of DTD document and is unable to produce
next token.
ParseException
is thrown if a DTD document does not comply with the DTD syntax
and the parser is unable to parse the document.
InputCharStream
- an implementation of interface
CharStream
.
Implements an input character
stream that maintains line and column number positions of the characters.
It also has the capability to backup the stream to some extent.java.io.Reader
reader and it is left to
constructor of the reader to set up character encoding correctly.
This means that method read of
the reader is used to get the next characters, assuming it returns
appropriate values. It is recommended to use class
java.io.InputStreamReader
as
a reader, which allows you to set the desired character encoding.
This class is an intermediate component between input
character reader and the parser.CharStream
, that
JavaCC would have generated with the following options set in
a JavaCC grammar file: JAVA_UNICODE_ESCAPE = false; UNICODE_INPUT = false; USER_CHAR_STREAM = false;Note that this class is not fully JavaCC generated.
The following example parses the XML DTD file dtd-document.dtd
and constructs the corresponding
XML DTD document
object dtd.
FileInputStream inputStream; InputStreamReader reader; InputCharStream charStream; DTDInitialParser initialParser; String intermedResult; StringReader strReader; DTDParser parser; DTDdocument dtd; // instantiate input byte stream, associated with the input file inputStream = new FileInputStream( "dtd-document.dtd" ); // instantiate character reader from the input file byte stream reader = new InputStreamReader( inputStream, "US-ASCII" ); // instantiate char stream for initial parser from the input reader charStream = new InputCharStream( reader ); // instantiate initial parser initialParser = new DTDInitialParser( charStream ); // get result of initial parsing - DTD text document with parameter // entity references expanded intermedResult = initialParser.Input(); // construct StringReader from the intermediate parsing result strReader= new StringReader( intermedResult ); // instantiate char stream for the main parser charStream = new InputCharStream( strReader ); // instantiate main parser parser = new DTDParser( charStream ); // parse intermediate parsing result with the main parser // and get corresponding DTD document oblect dtd = parser.Input();
Interface | Description |
---|---|
CharStream |
This interface describes a character stream that maintains line and
column number positions of the characters.
|
DTDInitialParserConstants | |
DTDParserConstants |
Class | Description |
---|---|
DTDInitialParser |
Initial XML DTD parser.
|
DTDInitialParserTokenManager | |
DTDParser |
Main XML DTD parser.
|
DTDParser.JJCalls | |
DTDParserTokenManager | |
InputCharStream |
An implementation of interface
CharStream . |
Token |
Describes the input token stream.
|
Exception | Description |
---|---|
ParseException |
This exception is thrown when parse errors are encountered.
|
Error | Description |
---|---|
TokenMgrError |
This Error is occurs if the Token Manager is unable to form next token
and pass it to the parser.
|
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com