hexpat-0.11: wrapper for expat, the fast XML parserSource codeContentsIndex
Text.XML.Expat.Annotated
Contents
Tree structure
Qualified nodes
Namespaced nodes
Deprecated parse functions
Parse to tree
SAX-style parse
Variants that throw exceptions
Abstraction of string types
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. It is assumed you will usually want Tree or Annotated, not both, so many of the names conflict.

Support for qualified and namespaced trees annotated with location information is not complete.

Synopsis
data Node tag text a
= Element {
eName :: !tag
eAttrs :: ![(tag, text)]
eChildren :: [Node tag text a]
eAnn :: a
}
| Text !text
type Attributes tag text = [(tag, text)]
type UNode text a = Node text text a
type UAttributes text = Attributes text text
type LNode tag text = Node tag text XMLParseLocation
type ULNode text = LNode text text
textContent :: Monoid text => Node tag text a -> text
unannotate :: Node tag text a -> Node tag text
data QName text = QName {
qnPrefix :: Maybe text
qnLocalPart :: !text
}
type QNode text a = Node (QName text) text a
type QAttributes text = Attributes (QName text) text
type QLNode text = LNode (QName text) text
data NName text = NName {
nnNamespace :: Maybe text
nnLocalPart :: !text
}
type NNode text a = Node (NName text) text a
type NAttributes text = Attributes (NName text) text
type NLNode text = LNode (NName text) text
mkNName :: text -> text -> NName text
mkAnNName :: text -> NName text
xmlnsUri :: GenericXMLString text => text
xmlns :: GenericXMLString text => 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
data Encoding
= ASCII
| UTF8
| UTF16
| ISO88591
data XMLParseError = XMLParseError String XMLParseLocation
data XMLParseLocation = XMLParseLocation {
xmlLineNumber :: Int64
xmlColumnNumber :: Int64
xmlByteIndex :: Int64
xmlByteCount :: Int64
}
parse :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> (LNode tag text, Maybe XMLParseError)
parse' :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> Either XMLParseError (LNode tag text)
parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> LNode tag text
data SAXEvent tag text
= StartElement tag [(tag, text)]
| EndElement tag
| CharacterData text
| FailDocument XMLParseError
saxToTree :: GenericXMLString tag => [(SAXEvent tag text, a)] -> (Node tag text a, Maybe XMLParseError)
data XMLParseException = XMLParseException 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
Tree structure
data Node tag text a Source
Annotated variant of the tree representation of the XML document.
Constructors
Element
eName :: !tag
eAttrs :: ![(tag, text)]
eChildren :: [Node tag text a]
eAnn :: a
Text !text
show/hide Instances
Functor (Node tag text)
(Eq tag, Eq text, Eq a) => Eq (Node tag text a)
(Show tag, Show text, Show a) => Show (Node tag text a)
(NFData tag, NFData text, NFData a) => NFData (Node tag text a)
type Attributes tag text = [(tag, text)]Source
Type shortcut for attributes
type UNode text a = Node text text aSource
Type shortcut for a single annotated node with unqualified tag names where tag and text are the same string type
type UAttributes text = Attributes text textSource
Type shortcut for attributes with unqualified names where tag and text are the same string type.
type LNode tag text = Node tag text XMLParseLocationSource
Type shortcut for a single annotated node, annotated with parse location
type ULNode text = LNode text textSource
Type shortcut for a single node with unqualified tag names where tag and text are the same string type, annotated with parse location
textContent :: Monoid text => Node tag text a -> textSource
Extract all text content from inside a tag into a single string, including any text contained in children.
unannotate :: Node tag text a -> Node tag textSource
Qualified nodes
data QName text Source

A qualified name.

Qualified names have two parts, a prefix and a local part. The local part is the name of the tag. The prefix scopes that name to a particular group of legal tags.

The prefix will usually be associated with a namespace URI. This is usually achieved by using xmlns attributes to bind prefixes to URIs.

Constructors
QName
qnPrefix :: Maybe text
qnLocalPart :: !text
show/hide Instances
Eq text => Eq (QName text)
Show text => Show (QName text)
NFData text => NFData (QName text)
type QNode text a = Node (QName text) text aSource
Type shortcut for a single annotated node where qualified names are used for tags
type QAttributes text = Attributes (QName text) textSource
Type shortcut for attributes with qualified names
type QLNode text = LNode (QName text) textSource
Type shortcut for a single node where qualified names are used for tags, annotated with parse location
Namespaced nodes
data NName text Source

A namespace-qualified tag.

NName has two components, a local part and an optional namespace. The local part is the name of the tag. The namespace is the URI identifying collections of declared tags. Tags with the same local part but from different namespaces are distinct. Unqualified tags are those with no namespace. They are in the default namespace, and all uses of an unqualified tag are equivalent.

Constructors
NName
nnNamespace :: Maybe text
nnLocalPart :: !text
show/hide Instances
Eq text => Eq (NName text)
Show text => Show (NName text)
NFData text => NFData (NName text)
type NNode text a = Node (NName text) text aSource
Type shortcut for a single annotated node where namespaced names are used for tags
type NAttributes text = Attributes (NName text) textSource
Type shortcut for attributes with namespaced names
type NLNode text = LNode (NName text) textSource
Type shortcut for a single node where namespaced names are used for tags, annotated with parse location
mkNName :: text -> text -> NName textSource
Make a new NName from a prefix and localPart.
mkAnNName :: text -> NName textSource
Make a new NName with no prefix.
xmlnsUri :: GenericXMLString text => textSource
xmlns :: GenericXMLString text => textSource
Deprecated parse functions
parseSAXSource
:: (GenericXMLString tag, GenericXMLString text)
=> Maybe EncodingInput text (a lazy ByteString)
-> 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 EncodingInput text (a lazy ByteString)
-> 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 EncodingInput text (a lazy ByteString)
-> 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 EncodingInput text (a lazy ByteString)
-> 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 EncodingInput text (a lazy ByteString)
-> 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 EncodingInput text (a strict ByteString)
-> 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 EncodingInput text (a lazy ByteString)
-> ByteString
-> LNode tag text

DEPRECATED: use parseThrowing instead

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

Parse to 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 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
parseSource
:: (GenericXMLString tag, GenericXMLString text)
=> ParserOptions tag textInput text (a lazy ByteString)
-> 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)
=> ParserOptions tag textInput text (a strict ByteString)
-> ByteString
-> Either XMLParseError (LNode tag text)
Strictly parse XML to tree. Returns error message or valid parsed tree.
parseThrowingSource
:: (GenericXMLString tag, GenericXMLString text)
=> ParserOptions tag textInput text (a lazy ByteString)
-> 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.

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 tag text a, Maybe XMLParseError)Source
A lower level function that lazily converts a SAX stream into a tree structure. Variant that takes annotations for start tags.
Variants that throw exceptions
data XMLParseException Source
An exception indicating an XML parse error, used by the ..Throwing variants.
Constructors
XMLParseException XMLParseError
show/hide Instances
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
Produced by Haddock version 2.6.0