A DTD, or Document Type Definition, is used for defining the grammar, that is, the structure, of an XML file. An XML parser uses the DTD as a validation reference while parsing and validating XML files.
A2:
The two parsers available for XML files are the SAX parser and the DOM parser. The parsers differ on the mechanism used for parsing an XML file. A SAX parser is a fast-processing event handler that performs validation using the DTD but leaves the responsibility for processing the contents of an XML file to the application developer. The DOM parser, on the other hand, generates a DOM tree of objects using the contents of an XML file. This DOM tree can be easily navigated to access and change the contents of the parsed XML file. The major drawback of the DOM parser is that it is resource intensive.