package ezxmlm

  1. Overview
  2. Docs

Module EzxmlmSource

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

Sourcetype node = ('a Xmlm.frag as 'a) Xmlm.frag

The type of a single XML tag

Sourcetype nodes = node list

The type of a list of XML tags

Sourceexception Tag_not_found of string

Raised by the query combinators

Reading XML values

Sourceval from_channel : in_channel -> Xmlm.dtd * nodes

Read an XML document from an in_channel

Sourceval from_string : string -> Xmlm.dtd * nodes

Read an XML document directly from a string

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

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

Writing XML values

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

Write an XML document to an out_channel

Sourceval 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.

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

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

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

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

Attribute handling

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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

Sourceval 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.

Sourceval 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.

Sourceval hd : nodes -> node

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

Sourceval 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.

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

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

Sourceval 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.

Sourceval 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.

Sourceval 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

Sourceval 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.

Sourceval 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

Sourceval 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.

Sourceval 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.

Sourceval 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.

OCaml

Innovation. Community. Security.