hexpat-0.4: 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 interface provided by 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 or parseChunk.
Synopsis
data Parser
newParser :: Maybe Encoding -> IO Parser
parse :: Parser -> ByteString -> IO (Maybe XMLParseError)
parseChunk :: Parser -> ByteString -> Bool -> IO (Maybe XMLParseError)
data Encoding
= ASCII
| UTF8
| UTF16
| ISO88591
data XMLParseError = XMLParseError String Integer Integer
type StartElementHandler = CString -> [(CString, CString)] -> IO Bool
type EndElementHandler = CString -> IO Bool
type CharacterDataHandler = CStringLen -> IO Bool
setStartElementHandler :: Parser -> StartElementHandler -> IO ()
setEndElementHandler :: Parser -> EndElementHandler -> IO ()
setCharacterDataHandler :: Parser -> CharacterDataHandler -> IO ()
unsafeParseChunk :: Parser -> ByteString -> Bool -> IO (Maybe XMLParseError)
withHandlers :: Parser -> IO a -> IO a
unsafeSetHandlers :: Parser -> IO ExpatHandlers
unsafeReleaseHandlers :: ExpatHandlers -> IO ()
data ExpatHandlers
encodingToString :: Encoding -> String
Parser Setup
data Parser Source
show/hide Instances
newParser :: Maybe Encoding -> IO ParserSource
Create a Parser. The encoding parameter, if provided, overrides the document's encoding declaration.
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.
parseChunk :: Parser -> 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, line number, and column number
Constructors
XMLParseError String Integer Integer
show/hide Instances
Parser Callbacks
type StartElementHandler = 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 = 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 = 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.
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.
Lower-level interface
unsafeParseChunk :: Parser -> ByteString -> Bool -> IO (Maybe XMLParseError)Source
This variant of parseChunk must either be called inside withHandlers (safest), or between unsafeSetHandlers and unsafeReleaseHandlers, and this will give you better performance than parseChunk if you process multiple chunks inside.
withHandlersSource
::
=> Parser
-> IO aComputation where unsafeParseChunk may be used
-> IO a
unsafeParseChunk is required to be called inside withHandlers. Safer than using unsafeSetHandlers / unsafeReleaseHandlers.
unsafeSetHandlers :: Parser -> IO ExpatHandlersSource
unsafeReleaseHandlers :: ExpatHandlers -> IO ()Source
data ExpatHandlers Source
Helpers
encodingToString :: Encoding -> StringSource
Produced by Haddock version 2.4.2