XML DTD Validaiton with dom\Writer.java

Q

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

✍: FYIcenter

A

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

Run the dom\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:

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp .;..\xercesSamples.jar;..\xercesImpl.jar;..\xml-apis.jar 
   dom.Writer -v UserError.xml

[Error] UserError.xml:14:8: The content of element type 
   "User" must match "(ID+,BirthDate+,Name+,Sex+)".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE User [
<!ELEMENT User (ID+,BirthDate+,Name+,Sex+)>
<!ELEMENT ID (#PCDATA)>
<!ELEMENT BirthDate (#PCDATA)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Sex (#PCDATA)>
]>
<User>
    <ID>101</ID>
    <Name>Frank Y. Ivy</Name>
</User>

 

Using Apache Xerces DOM Sample Programs

⇒⇒FAQ for Apache Xerces XML Parser

2017-11-11, 159👍, 0💬