DTDParser — Parses DTD information within an XML file.

This module defines the DTDParser class.

class admit.xmlio.DTDParser.DTDParser(xmlFile=None)[source]

Class for parsing a dtd and holding the data for validation with XML. Reads in the dtd information at the top of the given file and constructs a dictionary based on its contents. Validation is done against this dictionary. A customized DTD validator was needed as there is no dtd validator for the SAX parser in python at the time this code was written.

Parameters:

xmlFile : str

The xml file to read the dtd from. Default: None.

Attributes

xmlFile (str) The xml file to read the dtd from.
entities (dict) Dictionary for the memory model of the dtd.
at (AT) The current AT.

Methods

check(name[, attrib, value]) Method to check a node for validity.
checkAll() Method to check the dtd structure to see if all expected nodes were found.
checkAttribute(name, attrib[, value]) Method to check an attribute for validity.
parse([xmlFile]) Method to parse the xml file for dtd information
check(name, attrib=None, value=None)[source]

Method to check a node for validity. Validity includes correct name and data type.

Parameters:

name : str

The name of the node being checked

attrib : str

The attribute of the node being checked, if any. Default: None

value : str

The type of the attribute being checked (e.g. bt.INT) Default: None

checkAll()[source]

Method to check the dtd structure to see if all expected nodes were found.

Parameters:None
Returns:Boolean, whether or not all nodes were found
checkAttribute(name, attrib, value=None)[source]

Method to check an attribute for validity. Validity includes correct name and data type.

Parameters:

name : str

The name of the node being checked

attrib : str

The attribute of the node being checked, if any.

value : str

The type of the attribute being checked (e.g. bt.INT) Default: None

parse(xmlFile=None)[source]

Method to parse the xml file for dtd information

Parameters:

xmlFile : str

The name of the xml file to search, does not need to be specified if the file was given in the constructor. Default : None

Returns:

None