package FrontC

  1. Overview
  2. Docs

Provide types and pretty printing for XML.

type attr = string * string

Attribute representation.

type node =
  1. | TEXT of string
    (*

    Simple text

    *)
  2. | COM of string
    (*

    Commentary

    *)
  3. | PI of string * string
    (*

    Processing instruction

    *)
  4. | ELT of string * attr list * node list
    (*

    Element

    *)

Representation of nodes.

type document = {
  1. version : string;
    (*

    Version, usually 1.0

    *)
  2. encoding : string;
    (*

    Encoding (only current encoding supported now)

    *)
  3. standalone : bool;
    (*

    Standalone attribute

    *)
  4. element : node;
    (*

    Document root element

    *)
}

Representation of an XML document.

val new_simple_doc : node -> document

Build a simple document with default initialization.

  • parameter elt

    Main element of the document.

val new_doc : string -> string -> bool -> node -> document

Build a full document.

  • parameter vers

    XML version.

  • parameter enc

    Document encoding.

  • parameter sa

    Stand-alone attribute.

  • parameter elt

    Document element.

val new_attr : string -> string -> attr

Build an attribute.

  • parameter name

    Name of the attribute.

  • parameter cont

    Content of the attribute.

val new_elt : string -> attr list -> node list -> node

Build a new element.

  • parameter name

    Name of the element.

  • parameter attrs

    Attributes.

  • parameter children

    Children nodes.

val new_text : string -> node

Build a new text node.

  • parameter text

    Content of the node.

val add_children : node -> node list -> node

Add children to an element node.

  • parameter node

    Element to add to.

  • parameter children

    Children to add.

  • returns

    Passed element with children added to the end.

val escape_attr : string -> char -> string

Escape the given attribute value for output.

  • parameter text

    Text of the attribute.

  • parameter quote

    Quote character used for the attribute, either '"' or '\''.

val output_attr : out_channel -> (string * string) -> unit

Output an attribute.

  • parameter out

    Output channel.

  • parameter name

    Name of the attribute.

  • parameter text

    Value of the attribute.

val output_node : out_channel -> string -> node -> unit

Output a node on the given channel.

  • parameter out

    Channel to output to.

  • parameter node

    Node to output.

  • parameter indent

    Indentation.

val output_doc : out_channel -> document -> unit

Output an XML document to the given output channel.

  • parameter out

    Output channel.

  • parameter doc

    Document to output.

val output : document -> unit

Output the given XML document on the standard output.

  • parameter doc

    XML document to output.

val output_file : string -> document -> unit

Output the given XML document on the named file.

  • parameter filename

    Path to the file to write to.

  • parameter doc

    XML document to output.

  • raises Sys_error

    In case of error during opening of the file.

OCaml

Innovation. Community. Security.