package obus

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module OBus_xml_parserSource

Monadic xml parsing

This module implements a simple monadic xml parser.

It is intended to make it easy to write XML document parsers. In OBus it is used to parse introspection document.

Sourceexception Parse_failure of Xmlm.pos * string
Sourcetype xml_parser

Type of an xml parser. It is used to parse a sequence of arguments and children of an element.

Sourcetype 'a node

Type of a single xml node parser, returning a value of type 'a

Sourceval failwith : xml_parser -> string -> 'a

Fail at current position with the given error message

Sourceval input : Xmlm.input -> 'a node -> 'a

Run a parser on a xml input. If it fails it raises a Parse_failure

Parsing of attributes

For the following functions, the first argument is the attribute name and each letter mean:

  • o : the attribute is optionnal
  • r : the attribute is required
  • d : a default value is given
  • f : a associative list for the attribute value is specified.
Sourceval ar : xml_parser -> string -> string
Sourceval ao : xml_parser -> string -> string option
Sourceval ad : xml_parser -> string -> string -> string
Sourceval afr : xml_parser -> string -> (string * 'a) list -> 'a
Sourceval afo : xml_parser -> string -> (string * 'a) list -> 'a option
Sourceval afd : xml_parser -> string -> 'a -> (string * 'a) list -> 'a
Parsing of elements
Sourceval elt : string -> (xml_parser -> 'a) -> 'a node

elt typ parser creates a node parser. It will parse element of type typ. parser is used to parse the attributes and children of the element.

Note that parser must consume all children, if some are left unparsed the parsing will fail.

Sourceval pcdata : string node

pcdata f parse one PCData

Sourceval map : 'a node -> ('a -> 'b) -> 'b node

map node f wraps the result of a node parser with f

Sourceval union : 'a node list -> 'a node

union nodes Node parser which parses any node matched by one of the given node parsers

Modifiers
Sourceval one : xml_parser -> 'a node -> 'a

one node parse exactly one node with the given node parser. It will fail if there is 0 or more than one node matched by node.

Sourceval opt : xml_parser -> 'a node -> 'a option

same as one but do not fail if there is no node matched by node.

Sourceval any : xml_parser -> 'a node -> 'a list

any node Parse all element matched by node. The resulting list is in the same order as the order in which nodes appears in the xml.

OCaml

Innovation. Community. Security.