package obus
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4001c0756f8edd48a7d3a43ce9d984d3f3946abb627e63bf5ab2376f1b861c99
md5=218be0245e55bfa1d6fdd324bbedf568
doc/obus.internals/OBus_xml_parser/index.html
Module OBus_xml_parser
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.
exception Parse_failure of Xmlm.pos * stringType of an xml parser. It is used to parse a sequence of arguments and children of an element.
val failwith : xml_parser -> string -> 'aFail at current position with the given error message
val input : Xmlm.input -> 'a node -> 'aRun 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 optionnalr: the attribute is requiredd: a default value is givenf: a associative list for the attribute value is specified.
val ar : xml_parser -> string -> stringval ao : xml_parser -> string -> string optionval ad : xml_parser -> string -> string -> stringval afr : xml_parser -> string -> (string * 'a) list -> 'aval afo : xml_parser -> string -> (string * 'a) list -> 'a optionval afd : xml_parser -> string -> 'a -> (string * 'a) list -> 'aParsing of elements
val elt : string -> (xml_parser -> 'a) -> 'a nodeelt 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.
val pcdata : string nodepcdata f parse one PCData
union nodes Node parser which parses any node matched by one of the given node parsers
Modifiers
val one : xml_parser -> 'a node -> 'aone 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.
val opt : xml_parser -> 'a node -> 'a optionsame as one but do not fail if there is no node matched by node.
val any : xml_parser -> 'a node -> 'a listany 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.