hexpat-0.15.1: wrapper for expat, the fast XML parserSource codeContentsIndex
Text.XML.Expat.IO
Contents
Parser Setup
Parsing
Parser Callbacks
Lower-level interface
Helpers
Description

Low-level interface to Expat. Unless speed is paramount, this should normally be avoided in favour of the interfaces provided by Text.XML.Expat.SAX and Text.XML.Expat.Tree. Basic usage is:

  1. Make a new parser: newParser.
  2. Set up callbacks on the parser: setStartElementHandler, etc.
  3. Feed data into the parser: parse, parse' or parseChunk. Some of these functions must be wrapped in withParser.
Synopsis
data Parser
newParser :: Maybe Encoding -> IO Parser
parse :: Parser -> ByteString -> IO (Maybe XMLParseError)
parse' :: Parser -> ByteString -> IO (Maybe XMLParseError)
withParser :: Parser -> (ParserPtr -> IO a) -> IO a
type ParserPtr = Ptr Parser_struct
data Parser_struct
parseChunk :: ParserPtr -> ByteString -> Bool -> IO (Maybe XMLParseError)
data Encoding
= ASCII
| UTF8
| UTF16
| ISO88591
data XMLParseError = XMLParseError String XMLParseLocation
getParseLocation :: ParserPtr -> IO XMLParseLocation
data XMLParseLocation = XMLParseLocation {
xmlLineNumber :: Int64
xmlColumnNumber :: Int64
xmlByteIndex :: Int64
xmlByteCount :: Int64
}
type StartElementHandler = ParserPtr -> CString -> [(CString, CString)] -> IO Bool
type EndElementHandler = ParserPtr -> CString -> IO Bool
type CharacterDataHandler = ParserPtr -> CStringLen -> IO Bool
type ExternalEntityRefHandler = Parser -> CString -> CString -> CString -> CString -> IO Bool
type SkippedEntityHandler = ParserPtr -> CString -> Int -> IO Bool
setStartElementHandler :: Parser -> StartElementHandler -> IO ()
setEndElementHandler :: Parser -> EndElementHandler -> IO ()
setCharacterDataHandler :: Parser -> CharacterDataHandler -> IO ()
setExternalEntityRefHandler :: Parser -> ExternalEntityRefHandler -> IO ()
setSkippedEntityHandler :: Parser -> SkippedEntityHandler -> IO ()
setUseForeignDTD :: Parser -> Bool -> IO ()
parseExternalEntityReference :: Parser -> CString -> Maybe Encoding -> CStringLen -> IO Bool
data ExpatHandlers
encodingToString :: Encoding -> String
Parser Setup
data Parser Source
show/hide Instances
newParser :: Maybe Encoding -> IO ParserSource
Create a Parser.
Parsing
parse :: Parser -> ByteString -> IO (Maybe XMLParseError)Source
parse data feeds lazy ByteString data into a Parser. It returns Nothing on success, or Just the parse error.
parse' :: Parser -> ByteString -> IO (Maybe XMLParseError)Source
parse data feeds strict ByteString data into a Parser. It returns Nothing on success, or Just the parse error.
withParserSource
:: Parser
-> ParserPtr -> IO aComputation where parseChunk and other low-level functions may be used
-> IO a
Most of the low-level functions take a ParserPtr so are required to be called inside withParser.
type ParserPtr = Ptr Parser_structSource
data Parser_struct Source
Opaque parser type.
parseChunk :: ParserPtr -> ByteString -> Bool -> IO (Maybe XMLParseError)Source
parseChunk data False feeds strict ByteString data into a Parser. The end of the data is indicated by passing True for the final parameter. It returns Nothing on success, or Just the parse error.
data Encoding Source
Encoding types available for the document encoding.
Constructors
ASCII
UTF8
UTF16
ISO88591
data XMLParseError Source
Parse error, consisting of message text and error location
Constructors
XMLParseError String XMLParseLocation
show/hide Instances
getParseLocation :: ParserPtr -> IO XMLParseLocationSource
data XMLParseLocation Source
Specifies a location of an event within the input text
Constructors
XMLParseLocation
xmlLineNumber :: Int64Line number of the event
xmlColumnNumber :: Int64Column number of the event
xmlByteIndex :: Int64Byte index of event from start of document
xmlByteCount :: Int64The number of bytes in the event
show/hide Instances
Parser Callbacks
type StartElementHandler = ParserPtr -> CString -> [(CString, CString)] -> IO BoolSource
The type of the "element started" callback. The first parameter is the element name; the second are the (attribute, value) pairs. Return True to continue parsing as normal, or False to terminate the parse.
type EndElementHandler = ParserPtr -> CString -> IO BoolSource
The type of the "element ended" callback. The parameter is the element name. Return True to continue parsing as normal, or False to terminate the parse.
type CharacterDataHandler = ParserPtr -> CStringLen -> IO BoolSource
The type of the "character data" callback. The parameter is the character data processed. This callback may be called more than once while processing a single conceptual block of text. Return True to continue parsing as normal, or False to terminate the parse.
type ExternalEntityRefHandler = Parser -> CString -> CString -> CString -> CString -> IO BoolSource
The type of the "external entity reference" callback. See the expat documentation.
type SkippedEntityHandler = ParserPtr -> CString -> Int -> IO BoolSource

Set a skipped entity handler. This is called in two situations:

1. An entity reference is encountered for which no declaration has been read and this is not an error.

2. An internal entity reference is read, but not expanded, because XML_SetDefaultHandler has been called.

setStartElementHandler :: Parser -> StartElementHandler -> IO ()Source
Attach a StartElementHandler to a Parser.
setEndElementHandler :: Parser -> EndElementHandler -> IO ()Source
Attach an EndElementHandler to a Parser.
setCharacterDataHandler :: Parser -> CharacterDataHandler -> IO ()Source
Attach an CharacterDataHandler to a Parser.
setExternalEntityRefHandler :: Parser -> ExternalEntityRefHandler -> IO ()Source
setSkippedEntityHandler :: Parser -> SkippedEntityHandler -> IO ()Source
setUseForeignDTD :: Parser -> Bool -> IO ()Source
Lower-level interface
parseExternalEntityReferenceSource
:: Parser
-> CStringcontext
-> Maybe Encodingencoding
-> CStringLentext
-> IO Bool
data ExpatHandlers Source
Helpers
encodingToString :: Encoding -> StringSource
Produced by Haddock version 2.6.1