Page
Library
Module
Module type
Parameter
Class
Class type
Source
Dtd
SourceXml Light DTD
This module provide several functions to create, check, and use DTD to prove Xml documents :
Dtd.check
function can then be used to check that all DTD states have been declared, that no attributes are declared twice, and so on.Dtd.prove
function can be used to check an Xml
data structure with a checked DTD. The function will return the expanded Xml document or raise an exception if the DTD proving fails.Note about ENTITIES:
While parsing Xml, PCDATA is always parsed and the Xml entities & > < ' " are replaced by their corresponding ASCII characters. For Xml attributes, theses can be put between either double or simple quotes, and the backslash character can be used to escape inner quotes. There is no support for CDATA Xml nodes or PCDATA attributes declarations in DTD, and no support for user-defined entities using the ENTITY DTD element.
The DTD Types
type dtd_element_type = Xml_light_types.dtd_element_type =
| DTDEmpty
| DTDAny
| DTDChild of dtd_child
type dtd_item = Xml_light_types.dtd_item =
| DTDAttribute of string * string * dtd_attr_type * dtd_attr_default
| DTDElement of string * dtd_element_type
Parse the named file into a Dtd data structure. Raise Xml.File_not_found
if an error occured while opening the file. Raise Dtd.Parse_error
if parsing failed.
Read the content of the in_channel and parse it into a Dtd data structure. Raise Dtd.Parse_error
if parsing failed.
Parse the string containing a Dtd document into a Dtd data structure. Raise Dtd.Parse_error
if parsing failed.
Check the Dtd data structure declaration and return a checked DTD. Raise Dtd.Check_error
if the DTD checking failed.
Prove an Xml document using a checked DTD and an entry point. The entry point is the first excepted tag of the Xml document, the returned Xml document has the same structure has the original one, excepted that non declared optional attributes have been set to their default value specified in the DTD. Raise Dtd.Check_error
ElementNotDeclared
if the entry point is not found, raise Dtd.Prove_error
if the Xml document failed to be proved with the DTD.
Print a DTD element into a string. You can easily get a DTD document from a DTD data structure using for example String.concat "\n" (List.map Dtd.to_string) my_dtd
There is three types of DTD excecptions :
Dtd.Parse_error
is raised when an error occured while parsing a DTD document into a DTD data structure.Dtd.Check_error
is raised when an error occured while checking a DTD data structure for completeness, or when the prove entry point is not found when calling Dtd.prove
.Dtd.Prove_error
is raised when an error occured while proving an Xml document.Several string conversion functions are provided to enable you to report errors to the user.