|
|
|
|
|
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 = NodeG a [] | | | | type Attributes tag text = [(tag, text)] | | type UNode a text = Node a text text | | type UAttributes text = Attributes text text | | type LNode tag text = Node XMLParseLocation tag text | | type ULNode text = LNode text text | | textContent :: (NodeClass n [], Monoid text) => n [] tag text -> text | | isElement :: NodeClass n c => n c tag text -> Bool | | isNamed :: (NodeClass n c, Eq tag) => tag -> n c tag text -> Bool | | isText :: NodeClass n c => n c tag text -> Bool | | getName :: (NodeClass n c, Monoid tag) => n c tag text -> tag | | getAttributes :: NodeClass n c => n c tag text -> [(tag, text)] | | getAttribute :: (NodeClass n c, GenericXMLString tag) => n c tag text -> tag -> Maybe text | | getChildren :: NodeClass n c => n c tag text -> c (n c tag text) | | modifyName :: NodeClass n c => (tag -> tag) -> n c tag text -> n c tag text | | modifyAttributes :: NodeClass n c => ([(tag, text)] -> [(tag, text)]) -> n c tag text -> n c tag text | | setAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> text -> n c tag text -> n c tag text | | deleteAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> n c tag text -> n c tag text | | alterAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> Maybe text -> n c tag text -> n c tag text | | modifyChildren :: NodeClass n c => (c (n c tag text) -> c (n c tag text)) -> n c tag text -> n c tag text | | mapAllTags :: NodeClass n c => (tag -> tag') -> n c tag text -> n c tag' text | | unannotate :: Functor c => NodeG a c tag text -> NodeG c tag text | | modifyAnnotation :: (a -> a) -> Node a tag text -> Node a tag text | | mapAnnotation :: (a -> b) -> Node a tag text -> Node b tag text | | data QName text = QName {} | | type QNode a text = Node a (QName text) text | | type QAttributes text = Attributes (QName text) text | | type QLNode text = LNode (QName text) text | | toQualified :: (NodeClass n c, GenericXMLString text) => n c text text -> n c (QName text) text | | fromQualified :: (NodeClass n c, GenericXMLString text) => n c (QName text) text -> n c text text | | data NName text = NName {} | | type NNode text a = Node a (NName text) text | | type NAttributes text = Attributes (NName text) text | | type NLNode text = LNode (NName text) text | | mkNName :: text -> text -> NName text | | mkAnNName :: text -> NName text | | toNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Show text) => n c (QName text) text -> n c (NName text) text | | fromNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Functor c) => n c (NName text) text -> n c (QName text) text | | xmlnsUri :: GenericXMLString text => text | | xmlns :: GenericXMLString text => text | | data ParserOptions tag text = ParserOptions {} | | defaultParserOptions :: ParserOptions tag text | | | | 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) | | data XMLParseError = XMLParseError String XMLParseLocation | | data XMLParseLocation = XMLParseLocation {} | | parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> LNode tag text | | data XMLParseException = XMLParseException XMLParseError | | | | saxToTree :: GenericXMLString tag => [(SAXEvent tag text, a)] -> (Node a tag text, Maybe XMLParseError) | | class (Monoid s, Eq s) => GenericXMLString s where | | | 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 |
|
|
|
Tree structure
|
|
|
A pure tree representation that uses a list as its container type,
annotated variant.
|
|
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 usually [],
except when you are using chunked I/O with the hexpat-iteratee package.
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 | |
| Instances | |
|
|
type Attributes tag text = [(tag, text)] | Source |
|
Type shortcut for attributes
|
|
|
Type shortcut for a single annotated node with unqualified tag names where
tag and text are the same string type
|
|
|
Type shortcut for attributes with unqualified names where tag and
text are the same string type.
|
|
|
Type shortcut for a single annotated node, annotated with parse location
|
|
|
Type shortcut for a single node with unqualified tag names where
tag and text are the same string type, annotated with parse location
|
|
|
Extract all text content from inside a tag into a single string, including
any text contained in children.
|
|
|
Is the given node an element?
|
|
|
Is the given node a tag with the given name?
|
|
|
Is the given node text?
|
|
|
Get the name of this node if it's an element, return empty string otherwise.
|
|
|
Get the attributes of a node if it's an element, return empty list otherwise.
|
|
|
Get the value of the attribute having the specified name.
|
|
|
Get children of a node if it's an element, return empty list otherwise.
|
|
modifyName :: NodeClass n c => (tag -> tag) -> n c tag text -> n c tag text | Source |
|
Modify name if it's an element, no-op otherwise.
|
|
modifyAttributes :: NodeClass n c => ([(tag, text)] -> [(tag, text)]) -> n c tag text -> n c tag text | Source |
|
Modify attributes if it's an element, no-op otherwise.
|
|
|
Set the value of the attribute with the specified name to the value, overwriting
the first existing attribute with that name if present.
|
|
|
Delete the first attribute matching the specified name.
|
|
|
setAttribute if Just, deleteAttribute if Nothing.
|
|
modifyChildren :: NodeClass n c => (c (n c tag text) -> c (n c tag text)) -> n c tag text -> n c tag text | Source |
|
Modify children (non-recursively) if it's an element, no-op otherwise.
|
|
mapAllTags :: NodeClass n c => (tag -> tag') -> n c tag text -> n c tag' text | Source |
|
Map all tags (both tag names and attribute names) recursively.
|
|
Annotation-specific
|
|
|
Convert an annotated tree (Annotated module) into a non-annotated
tree (Tree module). Needed, for example, when you format your tree to
XML, since format takes a non-annotated tree.
|
|
modifyAnnotation :: (a -> a) -> Node a tag text -> Node a tag text | Source |
|
Modify this node's annotation (non-recursively) if it's an element, otherwise no-op.
|
|
|
Modify this node's annotation and all its children recursively if it's an element, otherwise no-op.
|
|
Qualified nodes
|
|
|
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 | |
|
| Instances | |
|
|
|
Type shortcut for a single annotated node where qualified names are used for tags
|
|
|
Type shortcut for attributes with qualified names
|
|
|
Type shortcut for a single node where qualified names are used for tags, annotated with parse location
|
|
|
|
|
|
Namespaced nodes
|
|
|
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 | |
|
| Instances | |
|
|
|
Type shortcut for a single annotated node where namespaced names are used for tags
|
|
|
Type shortcut for attributes with namespaced names
|
|
|
Type shortcut for a single node where namespaced names are used for tags, annotated with parse location
|
|
|
Make a new NName from a prefix and localPart.
|
|
|
Make a new NName with no prefix.
|
|
|
|
|
|
|
|
|
|
Parse to tree
|
|
data ParserOptions tag text | Source |
|
Constructors | ParserOptions | | parserEncoding :: Maybe Encoding | The 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
|
|
|
|
|
|
|
|
Encoding types available for the document encoding.
| Constructors | |
|
|
|
|
|
|
|
|
|
Parse error, consisting of message text and error location
| Constructors | | Instances | |
|
|
|
Specifies a location of an event within the input text
| Constructors | XMLParseLocation | | xmlLineNumber :: Int64 | Line number of the event
| xmlColumnNumber :: Int64 | Column number of the event
| xmlByteIndex :: Int64 | Byte index of event from start of document
| xmlByteCount :: Int64 | The number of bytes in the event
|
|
| Instances | |
|
|
Variant that throws exceptions
|
|
|
:: (GenericXMLString tag, GenericXMLString text) | | => ParserOptions tag text | Optional encoding override
| -> ByteString | Input 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.
|
|
|
|
An exception indicating an XML parse error, used by the ..Throwing variants.
| Constructors | | Instances | |
|
|
SAX-style parse
|
|
|
Constructors | StartElement tag [(tag, text)] | | EndElement tag | | CharacterData text | | FailDocument XMLParseError | |
| Instances | |
|
|
|
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
|
|
|
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 | | | Instances | |
|
|
Deprecated
|
|
|
|
|
|
|
|
|
|
|
|
|
parseSAXLocationsThrowing | Source |
|
|
|
|
|
|
|
|
|
|
|
|
Produced by Haddock version 2.6.1 |