Plasma GitLab Archive
Projects Blog Knowledge

Class Pxp_document.document


class [< clone : 'a; node : 'a node;
set_node : 'a node -> unit; .. >
as 'a]
document
: ?swarner:Pxp_types.symbolic_warnings -> Pxp_types.collect_warnings -> Pxp_types.rep_encoding -> object .. end
Documents are used to represent closed documents that may consist of an XML declaration, a DTD, and a node tree.

Important invariant: A document is either empty (no root element, no DTD), or it has both a root element and a DTD.

A fresh document created by new is empty.


method init_xml_version : string -> unit
Set the XML version string of the XML declaration.
method init_root : 'a node -> string -> unit
Set the root element. It is expected that the root element has a DTD. The second argument is the original name of the root element (without namespace prefix processing). Note that init_root checks whether the passed root element has the type expected by the DTD. The check takes into account that the root element might be a virtual root node.
method xml_version : string
Returns the XML version from the XML declaration. Returns "1.0" if the declaration is missing.
method xml_standalone : bool
Returns whether this document is declared as being standalone. This method returns the same value as 'standalone_declaration' of the DTD (if there is a DTD). Returns false if there is no DTD.
method dtd : Pxp_dtd.dtd
Returns the DTD of the root element. Fails if there is no root element.
method encoding : Pxp_types.rep_encoding
Returns the string encoding of the document = the encoding of the root element = the encoding of the element tree = the encoding of the DTD. Fails if there is no root element.
method root : 'a node
Returns the root element, or fails if there is not any.
method raw_root_name : string
The unprocessed name of the root element (second arg of init_root)
method add_pinstr : Pxp_dtd.proc_instruction -> unit
Adds a processing instruction to the document container. The parser does this for PIs occurring outside the DTD and outside the root element.
method pinstr : string -> Pxp_dtd.proc_instruction list
Return all PIs for a passed target string.
method pinstr_names : string list
Return all target strings of all PIs.

Writing documents as XML text

The write and display methods are very similar. The main difference is how namespaces are handled. When generating XML text, the namespaces need to be again represented as prefixes. The write method uses the normalized prefixes for this purpose. The display method uses the display prefixes, i.e. the prefixes as they orginally have been in the parsed XML text. This means for parsed XML text display produces an more exact copy of the text, whereas write shows the prefixes as they are seen by the program.

method write : ?default:string ->
?prefer_dtd_reference:bool ->
?dtd_style:[ `Auto | `Included | `Omit | `Reference ] ->
?minimization:[ `AllEmpty | `DeclaredEmpty | `None ] ->
Pxp_types.output_stream -> Pxp_types.encoding -> unit
Write the document to the passed output stream; the passed encoding used. The format is compact (the opposite of "pretty printing"). If a DTD is present, the DTD is included as internal subset.

Option ~default: Specifies the normprefix that becomes the default namespace in the output.

Option ~dtd_style: Selects how to print the DTD. `Omit means to omit the DTD at all (no DOCTYPE clause). `Reference prints the DTD reference to an external entity (using SYSTEM or PUBLIC identifier), if possible, and falls back to `Included otherwise. `Included means to always include the DTD as internal subset. `Auto tries to find the best way: If there is a DTD, try `Reference then `Included. Otherwise, `Omit. The default is `Included.

Option ~prefer_dtd_reference: Same as ~dtd_style:`Reference (backward-compatible).

Option ~minimization: How to write out empty elements. `AllEmpty means that all empty elements are minimized (using the <name/> form). `DeclaredEmpty minimizes only empty elements that are declared as empty in the DTD. `None does not minimize at all and is the default.

method display : ?prefer_dtd_reference:bool ->
?dtd_style:[ `Auto | `Included | `Omit | `Reference ] ->
?minimization:[ `AllEmpty | `DeclaredEmpty | `None ] ->
Pxp_types.output_stream -> Pxp_types.encoding -> unit
Write the document to the passed output stream; the passed encoding used. The format is compact (the opposite of "pretty printing"). If a DTD is present, the DTD is included as internal subset. In contrast to write, this method uses the display namespace prefixes instead of the normprefixes.

Option ~dtd_style: Same meaning as in write.

Option ~prefer_dtd_reference: Same meaning as in write.

Option ~minimization: Same meaning as in write.

method dump : Format.formatter -> unit
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml