hexpat-0.4: wrapper for expat, the fast XML parserSource codeContentsIndex
Text.XML.Expat.Tree
Contents
Tree structure
Parse to tree
SAX-style parse
Flavors
Description

This module provides functions to parse an XML document to a tree structure, either strictly or lazily, as well as a lazy SAX-style interface.

Extensible "flavors" give you the ability to use any string type. Three are provided here: String, ByteString and Text.

Synopsis
data Node tag text
= Element {
eName :: !tag
eAttrs :: ![(tag, text)]
eChildren :: [Node tag text]
}
| Text !text
parseTree :: TreeFlavor tag text -> Maybe Encoding -> ByteString -> (Node tag text, Maybe XMLParseError)
parseTree' :: TreeFlavor tag text -> Maybe Encoding -> ByteString -> Either XMLParseError (Node tag text)
data Encoding
= ASCII
| UTF8
| UTF16
| ISO88591
data XMLParseError = XMLParseError String Integer Integer
parseSAX :: TreeFlavor tag text -> Maybe Encoding -> ByteString -> [SAXEvent tag text]
data SAXEvent tag text
= StartElement tag [(tag, text)]
| EndElement tag
| CharacterData text
| FailDocument XMLParseError
data TreeFlavor tag text = TreeFlavor (CString -> IO tag) (CStringLen -> IO text) (tag -> Put) (text -> ByteString)
stringFlavor :: TreeFlavor String String
byteStringFlavor :: TreeFlavor ByteString ByteString
textFlavor :: TreeFlavor Text Text
Tree structure
data Node tag text Source
The tree representation of the XML document.
Constructors
Element
eName :: !tag
eAttrs :: ![(tag, text)]
eChildren :: [Node tag text]
Text !text
show/hide Instances
(Eq tag, Eq text) => Eq (Node tag text)
(Show tag, Show text) => Show (Node tag text)
(NFData tag, NFData text) => NFData (Node tag text)
Parse to tree
parseTreeSource
::
=> TreeFlavor tag textFlavor, which determines the string type to use in the tree
-> Maybe EncodingOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> (Node tag text, Maybe XMLParseError)
Lazily parse XML to tree. Note that forcing the XMLParseError return value will force the entire parse. Therefore, to ensure lazy operation, don't check the error status until you have processed the tree.
parseTree'Source
::
=> TreeFlavor tag textFlavor, which determines the string type to use in the output
-> Maybe EncodingOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> Either XMLParseError (Node tag text)
Strictly parse XML to tree. Returns error message or valid parsed tree.
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
SAX-style parse
parseSAXSource
::
=> TreeFlavor tag textFlavor, which determines the string type to use in the output
-> Maybe EncodingOptional encoding override
-> ByteStringInput 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.
data SAXEvent tag text Source
Constructors
StartElement tag [(tag, text)]
EndElement tag
CharacterData text
FailDocument XMLParseError
show/hide Instances
(Eq tag, Eq text) => Eq (SAXEvent tag text)
(Show tag, Show text) => Show (SAXEvent tag text)
(NFData tag, NFData text) => NFData (SAXEvent tag text)
Flavors
data TreeFlavor tag text Source
Constructors
TreeFlavor (CString -> IO tag) (CStringLen -> IO text) (tag -> Put) (text -> ByteString)
stringFlavor :: TreeFlavor String StringSource
Flavor for String data type.
byteStringFlavor :: TreeFlavor ByteString ByteStringSource
Flavor for ByteString data type, containing UTF-8 encoded Unicode.
textFlavor :: TreeFlavor Text TextSource
Flavor for Text data type.
Produced by Haddock version 2.4.2