Class DTDParser

  extended by org.jdom2.input.stax.DTDParser

public class DTDParser
extends java.lang.Object

Parses out key information from a single String representing a DOCTYPE declaration. StAX parsers supply a single string representing the DOCTYPE and this needs to be processed to get items like the SystemID, etc. Additionally it needs to be reformatted to create a standardised representation.

The assumption is that the DTD is valid.

We need to pull out 4 elements of data:

  1. The root element name
  2. The SystemID (if available)
  3. The PublicID (if available)
  4. The internal subset (if available)
The internal-subset should be re-formatted to conform to the JDOM 'standard' where each declaration starts on a new line indented with 2 spaces. This 'standard' is defined by the way that JDOM formats the DTD declarations in the SAX parse process, which fires individual events for the content in the DTD.

We can do this all with a well-structured regular expression, which is actually simpler than trying to fish out all the components ourselves....

Rolf Lear

Method Summary
static DocType parse(java.lang.String input, JDOMFactory factory)
          Parse out a DOCTYPE declaration as supplied by the standard StAX readers.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static DocType parse(java.lang.String input,
                            JDOMFactory factory)
                     throws JDOMException
Parse out a DOCTYPE declaration as supplied by the standard StAX readers.

Using 'XML' terminology, this method assumes that the input is both 'well-formed' and 'valid'. The assumptions that this class makes ensure that the 'right thing' is done for valid content, but invalid content may or may not fail with a JDOMException. The behaviour of this method with invalid input is 'undefined'.

input - the input DOCTYPE string to parse. Must be valid.
factory - The JDOM factory to use to build the JDOM DocType.
The input string as a DocType.
JDOMException - if the DocType is not generated.


Copyright 2013 Jason Hunter, Brett McLaughlin. All Rights Reserved.