4.2. Resolvers and sources

4.2.1. Using the built-in resolvers

The type source enumerates the various possibilities where the document to parse comes from.

type source =
    Entity of ((dtd -> Markup_entity.entity) * Markup_reader.resolver)
  | Channel of in_channel
  | File of string
  | Latin1 of string
  | ExtID of (ext_id * Markup_reader.resolver)

4.2.2. The resolver API

A resolver is an object that can be opened like a file, but you do not pass the file name to the resolver, but the XML identifier of the entity to read from (either a SYSTEM or PUBLIC clause). When opened, the resolver must return the Lexing.lexbuf that reads the characters. The resolver can be closed, and it can be cloned. Furthermore, it is possible to tell the resolver which character set it should assume. (Note: Markup works internally with ISO-8859-1, so the resolver must recode the characters into this character set.)

class type resolver =
  object
    method open_in : ext_id -> Lexing.lexbuf
    method close_in : unit
    method change_encoding : string -> unit
    method clone : resolver
  end
The resolver object must work as follows:

Example: How to define a resolver that is equivalent to Latin1.