ezxmlm

Combinators for parsing and selection of XML structures
Module Ezxmlm

Basic types

type node = 'a Xmlm.frag as 'a Xmlm.frag

The type of a single XML tag

type nodes = node list

The type of a list of XML tags

exception Tag_not_found of string

Raised by the query combinators

Reading XML values

val from_channel : in_channel -> Xmlm.dtd * nodes

Read an XML document from an in_channel

val from_string : string -> Xmlm.dtd * nodes

Read an XML document directly from a string

val from_input : Xmlm.input -> Xmlm.dtd * node

Low-level function to read directly from an Xmlm input source

Writing XML values

val to_channel : out_channel -> ?decl:bool -> Xmlm.dtd -> nodes -> unit

Write an XML document to an out_channel

val to_string : ?decl:bool -> ?dtd:string -> nodes -> string

Write an XML document to a string. This goes via an intermediate Buffer and so may be slow on large documents.

val to_output : Xmlm.output -> (Xmlm.dtd * node) -> unit

Low-level function to write directly to an Xmlm output source

val pp : Format.formatter -> nodes -> unit

pp fmt x will write a string representation of the XML document x to the formatter fmt.

Attribute handling

val filter_attrs : string -> string -> (Xmlm.attribute list * nodes) list -> (Xmlm.attribute list * nodes) list

Given some selected attributes and nodes (usually from members_with_attr) return the ones that match the class and value supplied.

val filter_attr : string -> string -> (Xmlm.attribute list * nodes) list -> Xmlm.attribute list * nodes

Given some selected attributes and nodes (usually from members_with_attr) return the first that matches the class and value supplied. Raises Not_found if nothing matches.

val mem_attr : string -> string -> Xmlm.attribute list -> bool

mem_attr name value attrs returns true if the name key is with value value is present in the attrs attribute list.

val get_attr : string -> Xmlm.attribute list -> string

get_attr name attrs returns the value associated with key name in the attrs attribute list. Raised Not_found if the attribute is not present.

Selectors and utility functions

val pick_tags : string -> string -> string -> nodes -> nodes

pick_tags tag attr value selects all the child nodes that match the tag name and contain an attribute with name tag and value.

val pick_tag : string -> string -> string -> nodes -> node

pick_tag tag attr value selects the first child node that matches the tag name and contain an attribute with name tag and value. Raises Not_found if no such node exists.

val hd : nodes -> node

Return the first tag in the list of nodes. Raises Not_found if the nodes are empty

val tl : nodes -> nodes

Return all the tags but the first one in a list of nodes. Returns an empty list if the list is empty.

val make_tag : string -> (Xmlm.attribute list * nodes) -> node

Make a tag given a tag name and body attributes and nodes

val data_to_string : nodes -> string

Convert a list of `Data fragments to a human-readable string. Any elements within the list are ignored, and multiple `Data fragments are concatenated.

val members_with_attr : string -> nodes -> (Xmlm.attribute list * nodes) list

Extracts the immediate subnodes that match the given tag name and return a tuple of the attributes associated with that tag and its child nodes.

val members : string -> nodes -> nodes list

Extracts the immediate subnodes that match the given tag name, and only return the contents of those tags (ignoring the attributes, which can be retrieved via the members_with_attr function

val member_with_attr : string -> nodes -> Xmlm.attribute list * nodes

Extracts the first subnode that match the given tag name, and raises Tag_not_found if it can't find it.

val member : string -> nodes -> nodes

Extracts the first subnode that match the given tag name, and raises Tag_not_found if it can't find it. Only the contents of the tag are returned (ignoring the attributes, which can be retrieved via the member_with_attr function instead

val has_member : string -> nodes -> bool

has_member tag subnodes returns true if the given tag name is present among the subnodes and false if it can't find it.

val filter_map : tag:string -> f:( Xmlm.attribute list -> nodes -> nodes ) -> nodes -> nodes

Traverses XML nodes and applies f to any tags that match the tag parameter. The result of the transformations is returned as a new set of nodes.

val filter_iter : tag:string -> f:( Xmlm.attribute list -> nodes -> unit ) -> nodes -> unit

Traverses XML nodes and applies f to any tags that match the tag parameter.