Prev Package | Next Package | Frames | No Frames |
Initial Parser
parses the input text, searches for parameter
entity declarations (i.e.Interface Summary | |
CharStream | This interface describes a character stream that maintains line and column number positions of the characters. |
DTDInitialParserConstants | |
DTDParserConstants |
Class Summary | |
DTDInitialParser | Initial XML DTD parser. |
DTDInitialParserTokenManager | |
DTDParser | Main XML DTD parser. |
DTDParser.JJCalls | |
DTDParserTokenManager | |
InputCharStream | An implementation of interface
CharStream . |
ParseException | This exception is thrown when parse errors are encountered. |
Token | Describes the input token stream. |
TokenMgrError | This Error is occurs if the Token Manager is unable to form next token and pass it to the parser. |
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"?>
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) - automated tool to generate Java programming
language parsers.
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 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 DTD syntax
and the parser is unable to parse the document.
InputCharStream
- an implementation of interface
CharStream
.
Implements 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 next characters, assuming it returns
appropriate values. It is recommended to use class
java.io.InputStreamReader
as
a reader, which allows to set 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.
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();