PrevNextUpHome SophiaFramework UNIVERSE 5.3

19.4. DTD and XML Schema

DTD and XML Schema are the grammars to validate whether or not a XML document is correctly formated when being parsed by a XML parser.

In DTD, data type cannot be defined, and its grammar is not described in XML.

In XML Schema, the syntax is described in XML format, features such as data type definition and namespace handling that not included in DTD are available.

SophiaFramework supports DTD and XML Schema. When DTD or XML Schema is used to parse a XML document, if there is some data that is not regulated by the grammar, error will occur.

19.4.1. Processing a XML Document with DTD

The processing of a XML document with DTD uses the following functions of SFXXMLDOMParser/SFXXMLSAXParser

Table 19.10. Function of processing XML documents with DTD

Purpose Function Name of the SFXXMLDOMParser class Function Name of the SFXXMLSAXParser class
Set the grammar used by the parser. SFXXMLDOMParser::SetGrammar SFXXMLSAXParser::SetGrammar
Verify the XML document by DTD. SFXXMLDOMParser::SetValidationDTD SFXXMLSAXParser::SetValidationDTD
Load the extended DTD file into the XML document with DTD. SFXXMLDOMParser::SetLoadExternalDTD SFXXMLSAXParser::SetLoadExternalDTD
[Note] Function of Loading External DTD File

If DTD is defined as a separate file with the XML document, SetLoadExternalDTD is set to true and DTD file is loaded.

The following operations can be used to get a SFXXMLDocumentType object from the XML tree object.

Table 19.11. Function of Processing DTD file

Function Name Description
GetEntities Get all the entities declared in DTD.
GetNotations Get all the notations declared in DTD.
GetPublicID Get the public ID of the external subset.
GetSystemID Get the system ID of the external subset.

19.4.2. Processing a XML Document with XML Schema

When processing XML documents with XML Schema, use the following functions of SFXXMLDOMParser or SFXXMLSAXParser class.

Table 19.12. Function of Processing XML Documents with XML Schema

Purpose Function Name of the SFXXMLDOMParser class Function Name of the SFXXMLSAXParser class
Set the grammar used by parser. SFXXMLDOMParser::SetGrammar SFXXMLSAXParser::SetGrammar
Proccess the XML schema. SFXXMLDOMParser::SetDoSchema SFXXMLSAXParser::SetDoSchema
Verify the XML document by XML schema. SFXXMLDOMParser::SetValidationSchema SFXXMLSAXParser::SetValidationSchema
Specify the XSD file of the XML document with the XML Schema. SFXXMLDOMParser::SetSchemaLocation SFXXMLSAXParser::SetSchemaLocation
[Note] Function of Setting Namespace

If SetDoNamespaces is "true", namespace can be set.