package csvfields
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=70e701910eec5842f34be30bfbcebcefa322ff6bb0592b1b1e99d95fa69ee8fb
md5=5cc70c390a8dce471f86c30d5d2a490b
doc/csvfields.xml-light/Xml_light/Xml/index.html
Module Xml_light.Xml
Xml Light
Xml Light is a minimal Xml parser & printer for OCaml. It provide few functions to parse a basic Xml document into an OCaml data structure and to print back the data structures to an Xml document.
Xml Light has also support for DTD (Document Type Definition).
(c)Copyright 2002-2003 Nicolas Cannasse
Xml Data Structure
An Xml node is either Element (tag-name, attributes, children) or PCData text
Xml Parsing
For easily parsing an Xml data source into an xml data structure, you can use theses functions. But if you want advanced parsing usage, please look at the XmlParser module. All the parsing functions can raise some exceptions, see the Exceptions section for more informations.
val parse_file : string -> xmlParse the named file into an Xml data structure.
val parse_in : in_channel -> xmlRead the content of the in_channel and parse it into an Xml data structure.
val parse_string : string -> xmlParse the string containing an Xml document into an Xml data structure.
val parse_string_with : XmlParser.t -> string -> xmlXml Exceptions
Several exceptions can be raised when parsing an Xml document :
Xml.Erroris raised when an xml parsing error occurs. theXml.error_msgtells you which error occured during parsing and theXml.error_poscan be used to retreive the document location where the error occured at.Xml.File_not_foundis raised when and error occured while opening a file with theXml.parse_filefunction or when a DTD file declared by the Xml document is not found (see theXmlParsermodule for more informations on how to handle the DTD file loading).
If the Xml document is containing a DTD, then some other exceptions can be raised, see the module Dtd for more informations.
type error_msg = Types.error_msg = exception Error of errorval error : error -> stringGet a full error message from an Xml error.
val error_msg : error_msg -> stringGet the Xml error message as a string.
val line : error_pos -> intGet the line the error occured at.
val range : error_pos -> int * intGet the relative character range (in current line) the error occured at.
val abs_range : error_pos -> int * intGet the absolute character range the error occured at.
Xml Functions
exception Not_element of xmlexception Not_pcdata of xmlval tag : xml -> stringtag xdata returns the tag value of the xml node. Raise Xml.Not_element if the xml is not an element
val pcdata : xml -> stringpcdata xdata returns the PCData value of the xml node. Raise Xml.Not_pcdata if the xml is not a PCData
val attribs : xml -> (string * string) listattribs xdata returns the attribute list of the xml node. First string if the attribute name, second string is attribute value. Raise Xml.Not_element if the xml is not an element
val attrib : xml -> string -> stringattrib xdata "href" returns the value of the "href" attribute of the xml node (attribute matching is case-insensitive). Raise Xml.No_attribute if the attribute does not exists in the node's attribute list Raise Xml.Not_element if the xml is not an element
children xdata returns the children list of the xml node Raise Xml.Not_element if the xml is not an element
iter f xdata calls f on all children of the xml node. Raise Xml.Not_element if the xml is not an element
map f xdata is equivalent to List.map f (Xml.children xdata) Raise Xml.Not_element if the xml is not an element
fold f init xdata is equivalent to List.fold_left f init (Xml.children xdata) Raise Xml.Not_element if the xml is not an element
Xml Printing
val to_string : xml -> stringPrint the xml data structure into a compact xml string (without any user-readable formating ).
val to_string_fmt : xml -> stringPrint the xml data structure into an user-readable string with tabs and lines break between different nodes.
val to_human_string : xml -> stringmodule type X = sig ... end