Parses C programs to an abstract syntax tree
Module Cxml
type attr = string * string

Attribute representation.

type node =
| TEXT of string(*

Simple text

| COM of string(*


| PI of string * string(*

Processing instruction

| ELT of string * attr list * node list(*



Representation of nodes.

type document = {
version : string;(*

Version, usually 1.0

encoding : string;(*

Encoding (only current encoding supported now)

standalone : bool;(*

Standalone attribute

element : node;(*

Document root element


Representation of an XML document.

val validate_identifiers : node -> ( node, node ) result

validate_identifiers elt validates that identifiers in the document are unique and non-empty.

  • since 4.1.0
val deduplicate : node -> node

deduplicate elt traverses elt and removes all sub-elements with duplicating identifiers.

When several elements have the same identifier the first (in the DSF traversal order) element is preserved and all subsequent are removed.

If all children of a parent are duplicates of some other elements, then the father is still preserved with an empty list of children (unless it is itself a duplicate of some other element).

  • since 4.1.0
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


  • 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


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.