This module provides functions to parse an XML document to a lazy stream of SAX events.
- data Encoding
- data XMLParseError = XMLParseError String XMLParseLocation
- data XMLParseLocation = XMLParseLocation {}
- data ParseOptions tag text = ParseOptions {
- overrideEncoding :: Maybe Encoding
- entityDecoder :: Maybe (tag -> Maybe text)
- data SAXEvent tag text
- = StartElement tag [(tag, text)]
- | EndElement tag
- | CharacterData text
- | FailDocument XMLParseError
- textFromCString :: GenericXMLString text => CString -> IO text
- parse :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [SAXEvent tag text]
- parseLocations :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [SAXEvent tag text]
- defaultParseOptions :: ParseOptions tag text
- data XMLParseException = XMLParseException XMLParseError
- setEntityDecoder :: (GenericXMLString tag, GenericXMLString text) => Parser -> (tag -> Maybe text) -> (ParserPtr -> text -> IO ()) -> IO ()
- class (Monoid s, Eq s) => GenericXMLString s where
- gxNullString :: s -> Bool
- gxToString :: s -> String
- gxFromString :: String -> s
- gxFromChar :: Char -> s
- gxHead :: s -> Char
- gxTail :: s -> s
- gxBreakOn :: Char -> s -> (s, s)
- gxFromCStringLen :: CStringLen -> IO s
- gxToByteString :: s -> ByteString
- parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
- parseSAXLocations :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseSAXLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
- type ParserOptions tag text = ParseOptions tag text
- defaultParserOptions :: ParseOptions tag text
XML primitives
data XMLParseError Source
Parse error, consisting of message text and error location
data XMLParseLocation Source
Specifies a location of an event within the input text
XMLParseLocation | |
|
SAX-style parse
data ParseOptions tag text Source
ParseOptions | |
|
StartElement tag [(tag, text)] | |
EndElement tag | |
CharacterData text | |
FailDocument XMLParseError |
textFromCString :: GenericXMLString text => CString -> IO textSource
Converts a CString
to a GenericXMLString
type.
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parser options |
-> ByteString | Input text (a lazy ByteString) |
-> [SAXEvent tag text] |
Lazily parse XML to SAX events. In the event of an error, FailDocument is the last element of the output list.
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parser options |
-> ByteString | Input text (a lazy ByteString) |
-> [(SAXEvent tag text, XMLParseLocation)] |
A variant of parseSAX that gives a document location with each SAX event.
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Optional encoding override |
-> ByteString | Input text (a lazy ByteString) |
-> [(SAXEvent tag text, XMLParseLocation)] |
A variant of parseSAX that gives a document location with each SAX event.
In the event of an error, throw XMLParseException
.
parseLocationsThrowing
can throw an exception from pure code, which is generally a bad
way to handle errors, because Haskell's lazy evaluation means it's hard to
predict where it will be thrown from. However, it may be acceptable in
situations where it's not expected during normal operation, depending on the
design of your program.
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parser options |
-> ByteString | input text (a lazy ByteString) |
-> [SAXEvent tag text] |
Lazily parse XML to SAX events. In the event of an error, throw
XMLParseException
.
parseThrowing
can throw an exception from pure code, which is generally a bad
way to handle errors, because Haskell's lazy evaluation means it's hard to
predict where it will be thrown from. However, it may be acceptable in
situations where it's not expected during normal operation, depending on the
design of your program.
defaultParseOptions :: ParseOptions tag textSource
Variants that throw exceptions
data XMLParseException Source
An exception indicating an XML parse error, used by the ..Throwing variants.
Helpers
:: (GenericXMLString tag, GenericXMLString text) | |
=> Parser | |
-> (tag -> Maybe text) | Entity decoder |
-> (ParserPtr -> text -> IO ()) | Code to insert character data into the document |
-> IO () |
A helper for configuring the hexpat parser to use the specified entity decoder.
Abstraction of string types
class (Monoid s, Eq s) => GenericXMLString s whereSource
An abstraction for any string type you want to use as xml text (that is,
attribute values or element text content). If you want to use a
new string type with hexpat, you must make it an instance of
GenericXMLString
.
gxNullString :: s -> BoolSource
gxToString :: s -> StringSource
gxFromString :: String -> sSource
gxFromChar :: Char -> sSource
gxBreakOn :: Char -> s -> (s, s)Source
gxFromCStringLen :: CStringLen -> IO sSource
gxToByteString :: s -> ByteStringSource
Deprecated parse functions
:: (GenericXMLString tag, GenericXMLString text) | |
=> Maybe Encoding | Optional encoding override |
-> ByteString | Input text (a lazy ByteString) |
-> [SAXEvent tag text] |
:: (GenericXMLString tag, GenericXMLString text) | |
=> Maybe Encoding | Optional encoding override |
-> ByteString | Input text (a lazy ByteString) |
-> [(SAXEvent tag text, XMLParseLocation)] |
DEPRECATED: Use parseLocations
instead.
A variant of parseSAX that gives a document location with each SAX event.
parseSAXLocationsThrowingSource
:: (GenericXMLString tag, GenericXMLString text) | |
=> Maybe Encoding | Optional encoding override |
-> ByteString | Input text (a lazy ByteString) |
-> [(SAXEvent tag text, XMLParseLocation)] |
DEPRECATED: Used parseLocationsThrowing
instead.
A variant of parseSAX that gives a document location with each SAX event.
In the event of an error, throw XMLParseException
.
:: (GenericXMLString tag, GenericXMLString text) | |
=> Maybe Encoding | Optional encoding override |
-> ByteString | Input text (a lazy ByteString) |
-> [SAXEvent tag text] |
DEPRECATED: Use parseThrowing
instead.
Lazily parse XML to SAX events. In the event of an error, throw
XMLParseException
.
type ParserOptions tag text = ParseOptions tag textSource
defaultParserOptions :: ParseOptions tag textSource
DEPRECATED. Renamed to defaultParseOptions.