---
name: "Xml_lexer"
section: "3o"
platform: "linux"
package: "liblablgtk2-ocaml-doc"
version: "2.4.0v0.2tv-8"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/Xml_lexer"
---

# Xml\_lexer(3o)

Simple XML lexer

## NAME

Xml\_lexer - Simple XML lexer

## Module

Module   Xml\_lexer

## Documentation

Module **Xml\_lexer**\
  :  **sig end**

Simple XML lexer

**=== This module provides an ocamllex lexer for XML files. It only** **supports the most basic features of the XML specification.** **The lexer altogether ignores the following 'events': comments,** **processing instructions, XML prolog and doctype declaration.** **The predefined entities (&amp;, &lt;, etc.) are supported. The** **replacement text for other entities whose entity value consist of** **character data can be provided to the lexer (see** **Xml\_lexer.entities). Internal entities declarations are not** **taken into account (the lexer just skips the doctype declaration).** **CDATA sections and character references are supported.** **See Xml\_lexer.strip\_ws about whitespace handling. ===**

**===** **Error reporting** **===**

*type error* =\
  \| Illegal\_character **of** **char**\
  \| Bad\_entity **of** **string**\
  \| Unterminated **of** **string**\
  \| Tag\_expected\
  \| Attribute\_expected\
  \| Other **of** **string**

*val error\_string* :  **error -\> string**

*exception Error* **of** **error \* int**

This exception is raised in case of an error during the parsing. The  **int** argument indicates the character position in the buffer. Note that some non-conforming XML documents might not trigger an error.

**===** **API** **===**

*type token* =\
  \| Tag **of** **string \* (string \* string) list \* bool**    (\*  **Tag (name, attributes, empty)** denotes an opening tag \
 	   with the specified  **name** and  **attributes** . If  **empty** , \
 	   then the tag ended in "/\>", meaning that it has no \
 	   sub-elements. \*)\
  \| Chars **of** **string**    (\* Some text between the tags \*)\
  \| Endtag **of** **string**    (\* A closing tag \*)\
  \| EOF  (\* End of input \*)

The type of the XML document elements

*val strip\_ws* :  **bool Pervasives.ref**

Whitespace handling: if  **strip\_ws** is  **true** (the default),  whitespaces next to a tag are ignored. Character data consisting  only of whitespaces is thus suppressed (i.e.  **Chars**  tokens are skipped).

*val entities* :  **(string \* string) list Pervasives.ref**

An association list of entities definitions. Initially, it contains the predefined entities ( **\["amp", & ; lt , \< ...\]** ).

*val token* :  **Lexing.lexbuf -\> token**

The entry point of the lexer.

**Raises Error** in case of an invalid XML document

**Returns** the next token in the buffer
