JDK Tutorials - Herong's Tutorial Examples - v6.32, by Herong Yang
Testing DOM XML DTD Validator
This section provides a tutorial example on how to test the DOM XML DTD Validator. All errors are generated with line numbers and explanations.
To test the DOMValidator.java program described in the previous section, I created the following XML file with DTD statements, invalid_dtd.xml:
<?xml version="1.0"?> <!-- invalid_dtd.xml - Copyright (c) HerongYang.com. All Rights Reserved. --> <!DOCTYPE dictionary [ <!ELEMENT dictionary (note, word+)> <!ELEMENT note ANY> <!ELEMENT word (update?, name, definition+, usage*)> <!ELEMENT update EMPTY> <!ATTLIST update date CDATA #REQUIRED editor CDATA #IMPLIED > <!ELEMENT name (#PCDATA)> <!ATTLIST name is_acronym (true | false) "false"> <!ELEMENT definition (#PCDATA)> <!ELEMENT usage (#PCDATA | i)*> <!ELEMENT i (#PCDATA)> <!ENTITY herong "Herong Yang"> ]> <dictionary> <note>Copyright (c) by &herong;</note> <word> <name is_acronym="true" language="EN">POP</name> <definition>Post Office Protocol</definition> <definition>Point Of Purchase</definition> </word> <word> <update date="2002-12-23"/> <name is_acronym="yes">XML</name> <definition>eXtensible Markup Language</definition> <note>XML comes from SGML</note> </word> <word> <update editor="Herong Yang"/> <name>markup</name> <definition>The amount added to the cost price to calculate the selling price - <i>Webster</i></definition> </word> </dictionary>
After running "java DOMValidator.java invalid_dtd.xml", I got:
Error: Public ID: null System ID: file:/C:/herong/dictionary_dtd.xml Line number: 24 Column number: 41 Message: Attribute "language" must be declared for element type "name". Error: Public ID: null System ID: file:/C:/herong/dictionary_dtd.xml Line number: 30 Column number: 26 Message: Attribute "is_acronym" with value "yes" must have a value from the list "true false ". Error: Public ID: null System ID: file:/C:/herong/dictionary_dtd.xml Line number: 33 Column number: 9 Message: The content of element type "word" must match "(update?,name,definition+,usage*)". Error: Public ID: null System ID: file:/C:/herong/dictionary_dtd.xml Line number: 35 Column number: 33 Message: Attribute "date" is required and must be specified for element type "update". Error: Public ID: null System ID: file:/C:/herong/dictionary_dtd.xml Line number: 38 Column number: 48 Message: The content of element type "definition" must match "null".
This is perfect. It tells you where the error is, and why it's an error.
Table of Contents
Date, Time and Calendar Classes
Date and Time Object and String Conversion
Number Object and Numeric String Conversion
Locales, Localization Methods and Resource Bundles
Calling and Importing Classes Defined in Unnamed Packages
HashSet, Vector, HashMap and Collection Classes
Character Set Encoding Classes and Methods
Encoding Conversion Programs for Encoded Text Files
Datagram Network Communication
DOM (Document Object Model) - API for XML Files
►DTD (Document Type Definition) - XML Validation
DOMValidator.java - XML DTD Validation with DOM
►Testing DOM XML DTD Validator
SAXValidator.java - XML DTD Validation with SAX
XSD (XML Schema Definition) - XML Validation
XSL (Extensible Stylesheet Language)
Message Digest Algorithm Implementations in JDK
Private key and Public Key Pair Generation
PKCS#8/X.509 Private/Public Encoding Standards
Digital Signature Algorithm and Sample Program
"keytool" Commands and "keystore" Files
KeyStore and Certificate Classes
Secret Key Generation and Management
Cipher - Encryption and Decryption
The SSL (Secure Socket Layer) Protocol
SSL Socket Communication Testing Programs