Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to read contents of an inline DocType using a SaxParser

843834Jan 26 2006
I'm working on a program that creates a tree structure based on the entire contents of an xml document. This includes all comments processing instructions and DocType definitions. I currently use a SaxParser with an extension of Default Handler to get the basic XML components and then I've registered a LexicalHandler that picks up comments etc. This allows me to detect everything except the DocType declaration.

So next I implemented the startDTD and endDTD methods within the DefaultHandler to get notifications about any DocType definitions. These methods provide the root-element name and the publicId or SystemId of the DocType declaration. This is exactly what I need for external DTD definitions. However, I can't work out how to get the contents of an inline DYD definition such as:

<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>

All that the startDTD method provides me is the root-element name 'root'. Does anyone know how I can find the contents of the DTD between the [...] in the DocType definition. Is the contents returned as part of another entity related method call? I did try using the DTDHandler thats part of the DefaultHandler and set this on the saxParser using setDTDHandler but the methods within it were never called.

Any help will be greatly approceiated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2006
Added on Jan 26 2006
0 comments
889 views