Module Expat


module Expat: sig .. end
The Ocaml Expat library provides an interface to the Expat XML Parser.

Expat is a library, written C, for parsing XML documents. It's the underlying for Mozilla, Perl's XML::Parser, Python's xml.parser.expat, and other open source XML parsers.

To use this library, link with ocamlc expat.cma or ocamlopt expat.cmxa
Author(s): Maas-Maarten Zeeman


type expat_parser 
The type of expat parsers

Parser Creation

val parser_create : encoding:string -> expat_parser
Create a new XML parser. If encoding is not empty, it specifies a character encoding to use for the document. This overrides the document encoding declaration. Expat has four built in encodings. US-ASCII, UTF-8, UTF-16, ISO-8859-1
val parser_create_ns : encoding:string -> separator:char -> expat_parser
Create a new XML parser that has namespace processing in effect

Parsing

val parse : expat_parser -> string -> unit
Let the parser parse a chunk of an XML document.
Raises Expat_error error
val parse_sub : expat_parser -> string -> int -> int -> unit
Let the parser parse a chunk of an XML document in a substring
Raises Expat_error error
val final : expat_parser -> unit
Inform the parser that the entire document has been parsed.

Handler Setting and Resetting

The strings that are passed to the handlers are always encoded in UTF-8. Your application is responsible for translation of these strings into other encodings.

Start element setting and resetting

val set_start_element_handler : expat_parser -> (string -> (string * string) list -> unit) -> unit
val reset_start_element_handler : expat_parser -> unit

End element setting and resetting

val set_end_element_handler : expat_parser -> (string -> unit) -> unit
val reset_end_element_handler : expat_parser -> unit

Character data hander setting and resetting

val set_character_data_handler : expat_parser -> (string -> unit) -> unit
val reset_character_data_handler : expat_parser -> unit

Processing Instruction handler setting and resetting

val set_processing_instruction_handler : expat_parser -> (string -> string -> unit) -> unit
val reset_processing_instruction_handler : expat_parser -> unit

Comment handler setting and resetting

val set_comment_handler : expat_parser -> (string -> unit) -> unit
val reset_comment_handler : expat_parser -> unit

CData Section handler setting and resetting

val set_start_cdata_handler : expat_parser -> (unit -> unit) -> unit
val reset_start_cdata_handler : expat_parser -> unit
val set_end_cdata_handler : expat_parser -> (unit -> unit) -> unit
val reset_end_cdata_handler : expat_parser -> unit

Default Handler setting and resetting

val set_default_handler : expat_parser -> (string -> unit) -> unit
val reset_default_handler : expat_parser -> unit

External Entity Ref Handler setting and resetting

val set_external_entity_ref_handler : expat_parser ->
(string option -> string option -> string -> string option -> unit) -> unit
val reset_external_entity_ref_handler : expat_parser -> unit

Parse Position Functions

val get_current_byte_index : expat_parser -> int
val get_current_column_number : expat_parser -> int
val get_current_line_number : expat_parser -> int
val get_current_byte_count : expat_parser -> int

Error Reporting


type xml_error =
| NONE
| NO_MEMORY
| SYNTAX
| NO_ELEMENTS
| INVALID_TOKEN
| UNCLOSED_TOKEN
| PARTIAL_CHAR
| TAG_MISMATCH
| DUPLICATE_ATTRIBUTE
| JUNK_AFTER_DOC_ELEMENT
| PARAM_ENTITY_REF
| UNDEFINED_ENTITY
| RECURSIVE_ENTITY_REF
| ASYNC_ENTITY
| BAD_CHAR_REF
| BINARY_ENTITY_REF
| ATTRIBUTE_EXTERNAL_ENTITY_REF
| MISPLACED_XML_PI
| UNKNOWN_ENCODING
| INCORRECT_ENCODING
| UNCLOSED_CDATA_SECTION
| EXTERNAL_ENTITY_HANDLING
| NOT_STANDALONE
| UNEXPECTED_STATE
| ENTITY_DECLARED_IN_PE
| FEATURE_REQUIRES_XML_DTD
| CANT_CHANGE_FEATURE_ONCE_PARSING
exception Expat_error of xml_error
Exception raised by parse function to report error conditions
val xml_error_to_string : xml_error -> string
Converts a xml_error to a string

Miscellaneous Functions


type xml_param_entity_parsing_choice =
| NEVER
| UNLESS_STANDALONE
| ALWAYS
Parameter entity handling types
val set_param_entity_parsing : expat_parser -> xml_param_entity_parsing_choice -> bool
Enable the parsing of parameter entities
val expat_version : unit -> string
Return the Expat library version as a string (e.g. "expat_1.95.1"