Module Ezxmlm
An "easy" interface on top of the Xmlm
library.
This version provides more convenient (but less flexible) input and output functions that go to and from string
values. This avoids the need to write signal code, which is useful for quick scripts that manipulate XML.
More advanced users should go straight to the Xmlm
library and use it directly, rather than be saddled with the Ezxmlm interface below.
Basic types
type nodes
= node list
The type of a list of XML tags
Reading XML values
val from_channel : Stdlib.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 : Stdlib.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 intermediateBuffer
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 : Stdlib.Format.formatter -> nodes -> unit
pp fmt x
will write a string representation of the XML documentx
to the formatterfmt
.
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 theclass
andvalue
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 theclass
andvalue
supplied. RaisesNot_found
if nothing matches.
Selectors and utility functions
val pick_tags : string -> string -> string -> nodes -> nodes
pick_tags tag attr value
selects all the child nodes that match thetag
name and contain an attribute with nametag
andvalue
.
val pick_tag : string -> string -> string -> nodes -> node
pick_tag tag attr value
selects the first child node that matches thetag
name and contain an attribute with nametag
andvalue
. RaisesNot_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 themembers_with_attr
function
val member_with_attr : string -> nodes -> Xmlm.attribute list * nodes
Extracts the first subnode that match the given
tag
name, and raisesTag_not_found
if it can't find it.
val member : string -> nodes -> nodes
Extracts the first subnode that match the given
tag
name, and raisesTag_not_found
if it can't find it. Only the contents of the tag are returned (ignoring the attributes, which can be retrieved via themember_with_attr
function instead
val has_member : string -> nodes -> bool
has_member tag subnodes
returns true if the giventag
name is present among the subnodes and false if it can't find it.