hexpat-0.17: XML parser/formatter based on expatSource codeContentsIndex
Text.XML.Expat.Annotated
Contents
Tree structure
Generic node manipulation
Annotation-specific
Qualified nodes
Namespaced nodes
Parse to tree
Variant that throws exceptions
SAX-style parse
Abstraction of string types
Deprecated
Description

A variant of Node in which Element nodes have an annotation of any type, and some concrete functions that annotate with the XML parse location.

The names conflict with those in Tree so you must use qualified import if you want to use both modules.

Synopsis
type Node a tag text = NodeG a [] tag text
data NodeG a c tag text
= Element {
eName :: !tag
eAttributes :: ![(tag, text)]
eChildren :: c (NodeG a c tag text)
eAnn :: a
}
| Text !text
type UNode a text = Node a text text
type LNode tag text = Node XMLParseLocation tag text
type ULNode text = LNode text text
module Text.XML.Expat.Internal.NodeClass
modifyAnnotation :: (a -> a) -> Node a tag text -> Node a tag text
mapAnnotation :: (a -> b) -> Node a tag text -> Node b tag text
type QNode a text = Node a (QName text) text
type QLNode text = LNode (QName text) text
module Text.XML.Expat.Internal.Qualified
type NNode a text = Node a (NName text) text
type NLNode text = LNode (NName text) text
module Text.XML.Expat.Internal.Namespaced
data ParseOptions tag text = ParseOptions {
defaultEncoding :: Maybe Encoding
entityDecoder :: Maybe (tag -> Maybe text)
}
defaultParseOptions :: ParseOptions tag text
data Encoding
= ASCII
| UTF8
| UTF16
| ISO88591
parse :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> (LNode tag text, Maybe XMLParseError)
parse' :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> Either XMLParseError (LNode tag text)
data XMLParseError = XMLParseError String XMLParseLocation
data XMLParseLocation = XMLParseLocation {
xmlLineNumber :: Int64
xmlColumnNumber :: Int64
xmlByteIndex :: Int64
xmlByteCount :: Int64
}
parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> LNode tag text
data XMLParseException = XMLParseException XMLParseError
data SAXEvent tag text
= StartElement tag [(tag, text)]
| EndElement tag
| CharacterData text
| FailDocument XMLParseError
saxToTree :: GenericXMLString tag => [(SAXEvent tag text, a)] -> (Node a tag text, Maybe XMLParseError)
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
eAttrs :: Node a tag text -> [(tag, text)]
parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
parseSAXThrowing :: (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)]
parseTree :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> (LNode tag text, Maybe XMLParseError)
parseTree' :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Either XMLParseError (LNode tag text)
parseTreeThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> LNode tag text
unannotate :: Functor c => NodeG a c tag text -> NodeG c tag text
type ParserOptions tag text = ParseOptions tag text
defaultParserOptions :: ParseOptions tag text
Tree structure
type Node a tag text = NodeG a [] tag textSource

A pure tree representation that uses a list as its container type, annotated variant.

In the hexpat package, a list of nodes has the type [Node tag text], but note that you can also use the more general type function ListOf to give a list of any node type, using that node's associated list type, e.g. ListOf (UNode Text).

data NodeG a c tag text Source

Annotated variant of the tree representation of the XML document, meaning that it has an extra piece of information of your choice attached to each Element.

c is the container type for the element's children, which is [] in the hexpat package, and a monadic list type for hexpat-iteratee.

tag is the tag type, which can either be one of several string types, or a special type from the Text.XML.Expat.Namespaced or Text.XML.Expat.Qualified modules.

text is the string type for text content.

a is the type of the annotation. One of the things this can be used for is to store the XML parse location, which is useful for error handling.

Note that some functions in the Text.XML.Expat.Cursor module need to create new nodes through the MkElementClass type class. Normally this can only be done if a is a Maybe type (so it can provide the Nothing value for the annotation on newly created nodes). Or, you can write your own MkElementClass instance. Apart from that, there is no requirement for a to be a Maybe type.

Constructors
Element
eName :: !tag
eAttributes :: ![(tag, text)]
eChildren :: c (NodeG a c tag text)
eAnn :: a
Text !text
show/hide Instances
(Functor c, List c) => MkElementClass (NodeG (Maybe a)) c
(Functor c, List c) => NodeClass (NodeG a) c
(Eq tag, Eq text, Eq a) => Eq (NodeG a [] tag text)
(Show tag, Show text, Show a) => Show (NodeG a [] tag text)
(NFData tag, NFData text, NFData a) => NFData (NodeG a [] tag text)
type UNode a text = Node a text textSource
Type alias for a single annotated node with unqualified tag names where tag and text are the same string type
type LNode tag text = Node XMLParseLocation tag textSource
Type alias for a single annotated node, annotated with parse location
type ULNode text = LNode text textSource
Type alias for a single node with unqualified tag names where tag and text are the same string type, annotated with parse location
Generic node manipulation
module Text.XML.Expat.Internal.NodeClass
Annotation-specific
modifyAnnotation :: (a -> a) -> Node a tag text -> Node a tag textSource
Modify this node's annotation (non-recursively) if it's an element, otherwise no-op.
mapAnnotation :: (a -> b) -> Node a tag text -> Node b tag textSource
Modify this node's annotation and all its children recursively if it's an element, otherwise no-op.
Qualified nodes
type QNode a text = Node a (QName text) textSource
Type alias for a single annotated node where qualified names are used for tags
type QLNode text = LNode (QName text) textSource
Type alias for a single node where qualified names are used for tags, annotated with parse location
module Text.XML.Expat.Internal.Qualified
Namespaced nodes
type NNode a text = Node a (NName text) textSource
Type alias for a single annotated node where namespaced names are used for tags
type NLNode text = LNode (NName text) textSource
Type alias for a single node where namespaced names are used for tags, annotated with parse location
module Text.XML.Expat.Internal.Namespaced
Parse to tree
data ParseOptions tag text Source
Constructors
ParseOptions
defaultEncoding :: Maybe EncodingThe encoding parameter, if provided, overrides the document's encoding declaration.
entityDecoder :: Maybe (tag -> Maybe text)If provided, entity references (i.e.   and friends) will be decoded into text using the supplied lookup function
defaultParseOptions :: ParseOptions tag textSource
data Encoding Source
Encoding types available for the document encoding.
Constructors
ASCII
UTF8
UTF16
ISO88591
parseSource
:: (GenericXMLString tag, GenericXMLString text)
=> ParseOptions tag textOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> (LNode 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.
parse'Source
:: (GenericXMLString tag, GenericXMLString text)
=> ParseOptions tag textOptional encoding override
-> ByteStringInput text (a strict ByteString)
-> Either XMLParseError (LNode tag text)
Strictly parse XML to tree. Returns error message or valid parsed tree.
data XMLParseError Source
Parse error, consisting of message text and error location
Constructors
XMLParseError String XMLParseLocation
show/hide Instances
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
Variant that throws exceptions
parseThrowingSource
:: (GenericXMLString tag, GenericXMLString text)
=> ParseOptions tag textOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> LNode tag text

Lazily parse XML to tree. 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.

data XMLParseException Source
An exception indicating an XML parse error, used by the ..Throwing variants.
Constructors
XMLParseException XMLParseError
show/hide Instances
SAX-style parse
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)
saxToTree :: GenericXMLString tag => [(SAXEvent tag text, a)] -> (Node a tag text, Maybe XMLParseError)Source
A lower level function that lazily converts a SAX stream into a tree structure. Variant that takes annotations for start tags.
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.
Methods
gxNullString :: s -> BoolSource
gxToString :: s -> StringSource
gxFromString :: String -> sSource
gxFromChar :: Char -> sSource
gxHead :: s -> CharSource
gxTail :: s -> sSource
gxBreakOn :: Char -> s -> (s, s)Source
gxFromCStringLen :: CStringLen -> IO sSource
gxToByteString :: s -> ByteStringSource
show/hide Instances
Deprecated
eAttrs :: Node a tag text -> [(tag, text)]Source
parseSAXSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> [SAXEvent tag text]

DEPRECATED: Use parse instead.

Lazily parse XML to SAX events. In the event of an error, FailDocument is the last element of the output list. Deprecated in favour of new parse

parseSAXThrowingSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput 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.

parseSAXLocationsSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput 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 EncodingOptional encoding override
-> ByteStringInput 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.

parseTreeSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> (LNode tag text, Maybe XMLParseError)

DEPRECATED: Use parse instead.

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
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput text (a strict ByteString)
-> Either XMLParseError (LNode tag text)

DEPRECATED: use parse instead.

Strictly parse XML to tree. Returns error message or valid parsed tree.

parseTreeThrowingSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingOptional encoding override
-> ByteStringInput text (a lazy ByteString)
-> LNode tag text

DEPRECATED: use parseThrowing instead

Lazily parse XML to tree. In the event of an error, throw XMLParseException.

unannotate :: Functor c => NodeG a c tag text -> NodeG c tag textSource
Convert an annotated tree (Annotated module) into a non-annotated tree (Tree module). DEPRECATED in favour of fromElement.
type ParserOptions tag text = ParseOptions tag textSource
defaultParserOptions :: ParseOptions tag textSource
DEPRECATED. Renamed to defaultParseOptions.
Produced by Haddock version 2.6.1