org.exolab.castor.xml.dtd.parser

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » castor » org.exolab.castor.xml.dtd.parser 
org.exolab.castor.xml.dtd.parser

The XML DTD Parser API

Version:
$Revision: 6213 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
Author:
Alexander Totok
This package consists of two parsers:
  • {@link org.exolab.castor.xml.dtd.parser.DTDInitialParser 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".
    The initial parser parses internal parameter entity declarations only, like:
    <!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.
    The output of this parser is a document without paramater entity declarations and all parameter entity references substituted by corresponding replacement text.
  • {@link org.exolab.castor.xml.dtd.parser.DTDParser Main Parser} performes the main parsing process. It is able to parse:
    • ELEMENT declarations
    • ATTRIBUTE declarations
    • GENERAL ENTITY declarations
    • NOTATION declarations
    • Comments
    The parser does not parse:
    • Conditional Sections:
      <![ INCLUDE [ ... ]]>
      <![ IGNORE  [ ... ]]> 
    • Processing Instructions, like:
      <?xml version="1.0" encoding="UTF-16"?> 
    The parser does not expand general entity references or character references occurring within attribute and entity values.

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 {@link java.io.Reader 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.jj - initial parser's JavaCC grammar file with the syntax specification and processing code. This file is used by JavaCC to automatically generate Java classes for the initial parser.
  • {@link org.exolab.castor.xml.dtd.parser.DTDInitialParser DTDInitialParser}, {@link org.exolab.castor.xml.dtd.parser.DTDInitialParserConstants DTDInitialParserConstants}, {@link org.exolab.castor.xml.dtd.parser.DTDInitialParserTokenManager DTDInitialParserTokenManager} - classes of the initial parser automatically generated by JavaCC from the DTDInitialParser.jj file.
  • DTDParser.jj - main parser's JavaCC grammar file with the syntax specification and processing code. This file is used by JavaCC to automatically generate Java classes for the main parser.
  • {@link org.exolab.castor.xml.dtd.parser.DTDParser DTDParser}, {@link org.exolab.castor.xml.dtd.parser.DTDParserConstants DTDParserConstants}, {@link org.exolab.castor.xml.dtd.parser.DTDParserTokenManager DTDParserTokenManager} - classes of the main parser automatically generated by JavaCC from the DTDParser.jj file.
  • {@link org.exolab.castor.xml.dtd.parser.Token Token}, {@link org.exolab.castor.xml.dtd.parser.ParseException ParseException}, {@link org.exolab.castor.xml.dtd.parser.TokenMgrError TokenMgrError}, {@link org.exolab.castor.xml.dtd.parser.CharStream 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.
    {@link org.exolab.castor.xml.dtd.parser.TokenMgrError 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.
    {@link org.exolab.castor.xml.dtd.parser.ParseException ParseException} is thrown if a DTD document does not comply with the DTD syntax and the parser is unable to parse the document.
  • {@link org.exolab.castor.xml.dtd.parser.InputCharStream InputCharStream} - an implementation of interface {@link org.exolab.castor.xml.dtd.parser.CharStream 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.
    The object of this class is constructed using a {@link java.io.Reader 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 {@link java.io.InputStreamReader 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.
    The code of this class is based on the class ASCII_CharStream - implementation of interface {@link org.exolab.castor.xml.dtd.parser.CharStream 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 {@link org.exolab.castor.xml.dtd.DTDdocument 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();
    
Java Source File NameTypeComment
CharStream.javaInterface This interface describes a character stream that maintains line and column number positions of the characters.
DTDInitialParser.javaClass Initial XML DTD parser.
DTDInitialParserConstants.javaInterface
DTDInitialParserTokenManager.javaClass
DTDParser.javaClass Main XML DTD parser.
DTDParserConstants.javaInterface
DTDParserTokenManager.javaClass
InputCharStream.javaClass An implementation of interface org.exolab.castor.xml.dtd.parser.CharStream 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.
The object of this class is constructed using java.io.Reader 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.
ParseException.javaClass This exception is thrown when parse errors are encountered.
Token.javaClass Describes the input token stream.
TokenMgrError.javaClass This Error is occurs if the Token Manager is unable to form next token and pass it to the parser.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.