XML DTD Validaiton with sax\Writer.java


How to perform XML DTD validation with sax\Writer.java provided in the Apache Xerces package?

✍: FYIcenter


You can perform XML DTD validation with the sax\Writer.java program provided in the Apache Xerces package as shown below.

Run the sax\Writer.java program with "-v" option to turn on validation. If the input XML file does not meet the requirements of its DTD, you will see validation errors:

   -cp .;..\xercesImpl.jar sax.Writer -v UserError.xml
<?xml version="1.0" encoding="UTF-8"?>
    <Name>Frank Y. Ivy</Name>
[Error] UserError.xml:14:8: The content of element type "User" must match "(ID+,

The XML file with DTD used in the above test is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) 2017 FYIcenter.com -->
<!DOCTYPE User [
   <!ELEMENT User (ID+, BirthDate+, Name+, Sex+)>
   <!ELEMENT BirthDate (#PCDATA)>
   <!ELEMENT Name (#PCDATA)>

    <Name>Frank Y. Ivy</Name>


XML Schema Validaiton with sax\Writer.java

JAR Files Required to Run sax\Writer.java

Using Apache Xerces SAX Sample Programs

⇑⇑ FAQ for Apache Xerces XML Parser

2017-10-08, 2476👍, 0💬