Validating XML

The second parameter to XmlParser.getDocument tells the parser that we want to validate the XML against its DTD.
SAXParseException
...
+ getColumnNumber() : int
+ getLineNumber() : int
+ getMessage() : String
This has a number of benefits:
  • Simplifies the code because the document structure is assured.
  • Reduces the error handling code to a minimum.
  • Provides helpful error messages when validation fails.
  • Provides line numbers to help the user locate the source of the error.
public class SSDoDialogBox extends ScriptCommandBasics {
    ...

    public void doCommand() throws Exception {
        ...
        Document doc;
    
        try {
            doc = XmlParser.getDocument(input, true);
        } catch (SAXParseException exception) {
            throw new BadDataException(
                    "Error in resource " + resource + "', "
                  + ", line " + exception.getLineNumber() 
                  + ": "      + exception.getMessage());
        }
        ...
        XMLDialog dialog = new XMLDialog(frame, doc, context);
        ...
    }
}