Chapter 3. The objects representing the document

Table of Contents
3.1. The document class
3.2. The class type node
3.3. The class type extension
3.4. Details of the mapping from XML text to the tree representation
3.5. Namespaces

This description might be out-of-date. See the module interface files for updated information.

3.1. The document class

class [ 'ext ] document :
  Pxp_types.collect_warnings -> 
  object
    method init_xml_version : string -> unit
    method init_root : 'ext node -> unit

    method xml_version : string
    method xml_standalone : bool
    method dtd : dtd
    method root : 'ext node

    method encoding : Pxp_types.rep_encoding

    method add_pinstr : proc_instruction -> unit
    method pinstr : string -> proc_instruction list
    method pinstr_names : string list

    method write : Pxp_types.output_stream -> Pxp_types.encoding -> unit

  end
;;
The methods beginning with init_ are only for internal use of the parser.

  • xml_version: returns the version string at the beginning of the document. For example, "1.0" is returned if the document begins with <?xml version="1.0"?>.

  • xml_standalone: returns the boolean value of standalone declaration in the XML declaration. If the standalone attribute is missing, false is returned.

  • dtd: returns a reference to the global DTD object.

  • root: returns a reference to the root element.

  • encoding: returns the internal encoding of the document. This means that all strings of which the document consists are encoded in this character set.

  • pinstr: returns the processing instructions outside the DTD and outside the root element. The argument passed to the method names a target, and the method returns all instructions with this target. The target is the first word inside <? and ?>.

  • pinstr_names: returns the names of the processing instructions

  • add_pinstr: adds another processing instruction. This method is used by the parser itself to enter the instructions returned by pinstr, but you can also enter additional instructions.

  • write: writes the document to the passed stream as XML text using the passed (external) encoding. The generated text is always valid XML and can be parsed by PXP; however, the text is badly formatted (this is not a pretty printer).