Parsing Flow of XML Document with DTD Declarations

Q

How to show the parsing flow of XML documents with DTD declarations?

✍: FYIcenter

A

You can show the parsing flow of XML documents with DTD declarations with the sax\DocumentTracer.java program provided in the Apache Xerces package as shown below.

Compile and run sax\DocumentTracer.java program on the sample XML file UserDTD.xml:

\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java 
   -cp .;..\xercesImpl.jar sax.DocumentTracer UserDTD.xml
   
setDocumentLocator(locator=org.apache.xerces.parsers.AbstractSAXParser$LocatorPr
oxy@69663380)
startDocument()
 comment(text=" Copyright (c) 2017 FYIcenter.com ")
 startDTD(name="User",publicId=null,systemId=null)
  elementDecl(name="User",contentModel="(ID,BirthDate,Name,Sex)")
  elementDecl(name="ID",contentModel="(#PCDATA)")
  elementDecl(name="BirthDate",contentModel="(#PCDATA)")
  elementDecl(name="Name",contentModel="(#PCDATA)")
  elementDecl(name="Sex",contentModel="(#PCDATA)")
 endDTD()
 startElement(uri="",localName="User",qname="User",attributes={})
  ignorableWhitespace(text="\n    ")
  startElement(uri="",localName="ID",qname="ID",attributes={})
   characters(text="101")
  endElement(uri="",localName="ID",qname="ID")
  ignorableWhitespace(text="\n    ")
  startElement(uri="",localName="BirthDate",qname="BirthDate",attributes={})
   characters(text="1970-01-01+00:01")
  endElement(uri="",localName="BirthDate",qname="BirthDate")
  ignorableWhitespace(text="\n    ")
  startElement(uri="",localName="Name",qname="Name",attributes={})
   characters(text="Frank Y. Ivy")
  endElement(uri="",localName="Name",qname="Name")
  ignorableWhitespace(text="\n    ")
  startElement(uri="",localName="Sex",qname="Sex",attributes={})
   characters(text="  Male")
  endElement(uri="",localName="Sex",qname="Sex")
  ignorableWhitespace(text="\n")
 endElement(uri="",localName="User",qname="User")
endDocument()

 

Using Apache Xerces SAX Sample Programs

⇒⇒FAQ for Apache Xerces XML Parser

2017-07-30, 153👍, 0💬