hexpat-0.20.13: XML parser/formatter based on expat

Safe Haskell | None
Language | Haskell98

Text.XML.Expat.Extended

Contents

- Tree structure
- Generic document/node manipulation
- Annotation-specific
- Qualified nodes
- Namespaced nodes
- Parse to tree
- Variant that throws exceptions
- Convert from SAX
- Abstraction of string types

Description

An extended variant of Node intended to implement the entire XML specification. DTDs are not yet supported, however.

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

Synopsis

- type Document a tag text = DocumentG a [] tag text
- data DocumentG a (c :: Type -> Type) tag text = Document {
  - dXMLDeclaration :: Maybe (XMLDeclaration text)
  - dDocumentTypeDeclaration :: Maybe (DocumentTypeDeclaration c tag text)
  - dTopLevelMiscs :: c (Misc text)
  - dRoot :: NodeG a c tag text
  }
- type Node a tag text = NodeG a [] tag text
- data NodeG a (c :: Type -> Type) tag text
  - = Element {
    - eName :: !tag
    - eAttributes :: ![(tag, text)]
    - eChildren :: c (NodeG a c tag text)
    - eAnn :: a
    }
  - | Text !text
  - | CData !text
  - | Misc (Misc text)
- type UDocument a text = Document a text text
- type LDocument tag text = Document XMLParseLocation tag text
- type ULDocument text = Document XMLParseLocation 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.DocumentClass
- 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
- mapDocumentAnnotation :: (a -> b) -> Document a tag text -> Document b tag text
- type QDocument a text = Document a (QName text) text
- type QLDocument text = Document XMLParseLocation (QName text) text
- type QNode a text = Node a (QName text) text
- type QLNode text = LNode (QName text) text
- module Text.XML.Expat.Internal.Qualified
- type NDocument a text = Document a (NName text) text
- type NLDocument text = Document XMLParseLocation (NName text) text
- 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 {
  - overrideEncoding :: 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 -> (LDocument tag text, Maybe XMLParseError)
- parse' :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> Either XMLParseError (LDocument 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 -> LDocument tag text
- data XMLParseException = XMLParseException XMLParseError
- saxToTree :: (GenericXMLString tag, Monoid text) => [(SAXEvent tag text, a)] -> (Document 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)
  - gxFromByteString :: ByteString -> s
  - gxToByteString :: s -> ByteString

# Tree structure

type Document a tag text = DocumentG a [] tag text Source #

A pure representation of an XML document that uses a list as its container type.

data DocumentG a (c :: Type -> Type) tag text Source #

Document representation of the XML document, intended to support the entire XML specification. DTDs are not yet supported, however.

Constructors

Document |

Fields

- dXMLDeclaration :: Maybe (XMLDeclaration text)
- dDocumentTypeDeclaration :: Maybe (DocumentTypeDeclaration c tag text)
- dTopLevelMiscs :: c (Misc text)
- dRoot :: NodeG a c tag text

#### Instances

Instances details

(Functor c, List c) => DocumentClass (DocumentG ann) c Source # |

Instance details

Defined in Text.XML.Expat.Extended

Methods

getXMLDeclaration :: DocumentG ann c tag text -> Maybe (XMLDeclaration text) Source #

getDocumentTypeDeclaration :: DocumentG ann c tag text -> Maybe (DocumentTypeDeclaration c tag text) Source #

getTopLevelMiscs :: DocumentG ann c tag text -> c (Misc text) Source #

getRoot :: DocumentG ann c tag text -> NodeType (DocumentG ann) c tag text Source #

mkDocument :: Maybe (XMLDeclaration text) -> Maybe (DocumentTypeDeclaration c tag text) -> c (Misc text) -> NodeType (DocumentG ann) c tag text -> DocumentG ann c tag text Source #

(Show tag, Show text, Show a) => Show (DocumentG a [] tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended Methods showsPrec :: Int -> DocumentG a [] tag text -> ShowS Source # show :: DocumentG a [] tag text -> String Source # showList :: [DocumentG a [] tag text] -> ShowS Source #
(Eq tag, Eq text, Eq a) => Eq (DocumentG a [] tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended Methods (==) :: DocumentG a [] tag text -> DocumentG a [] tag text -> Bool Source # (/=) :: DocumentG a [] tag text -> DocumentG a [] tag text -> Bool Source #
type NodeType (DocumentG ann) Source # |
Instance details Defined in Text.XML.Expat.Extended type NodeType (DocumentG ann) = NodeG ann

type Node a tag text = NodeG a [] tag text Source #

A pure tree representation that uses a list as its container type, extended 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 :: Type -> Type) tag text Source #

Extended variant of the tree representation of the XML document, intended to support the entire XML specification. DTDs are not yet supported, however.

`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 or () (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 |

Fields

- eName :: !tag
- eAttributes :: ![(tag, text)]
- eChildren :: c (NodeG a c tag text)
- eAnn :: a

Text !text |
CData !text |
Misc (Misc text) |

#### Instances

Instances details

(Functor c, List c) => MkElementClass (NodeG (Maybe a)) c Source # |
Instance details Defined in Text.XML.Expat.Extended Methods mkElement :: tag -> Attributes tag text -> c (NodeG (Maybe a) c tag text) -> NodeG (Maybe a) c tag text Source #
(Functor c, List c) => MkElementClass (NodeG ()) c Source # |
Instance details Defined in Text.XML.Expat.Extended Methods mkElement :: tag -> Attributes tag text -> c (NodeG () c tag text) -> NodeG () c tag text Source #
(Functor c, List c) => NodeClass (NodeG a) c Source # |

Instance details

Defined in Text.XML.Expat.Extended

Methods

isElement :: NodeG a c tag text -> Bool Source #

isText :: NodeG a c tag text -> Bool Source #

isCData :: NodeG a c tag text -> Bool Source #

isProcessingInstruction :: NodeG a c tag text -> Bool Source #

isComment :: NodeG a c tag text -> Bool Source #

textContentM :: Monoid text => NodeG a c tag text -> ItemM c text Source #

isNamed :: Eq tag => tag -> NodeG a c tag text -> Bool Source #

getName :: Monoid tag => NodeG a c tag text -> tag Source #

hasTarget :: Eq text => text -> NodeG a c tag text -> Bool Source #

getTarget :: Monoid text => NodeG a c tag text -> text Source #

getAttributes :: NodeG a c tag text -> [(tag, text)] Source #

getChildren :: NodeG a c tag text -> c (NodeG a c tag text) Source #

getText :: Monoid text => NodeG a c tag text -> text Source #

modifyName :: (tag -> tag) -> NodeG a c tag text -> NodeG a c tag text Source #

modifyAttributes :: ([(tag, text)] -> [(tag, text)]) -> NodeG a c tag text -> NodeG a c tag text Source #

modifyChildren :: (c (NodeG a c tag text) -> c (NodeG a c tag text)) -> NodeG a c tag text -> NodeG a c tag text Source #

modifyElement :: ((tag, [(tag, text)], c (NodeG a c tag text)) -> (tag', [(tag', text)], c (NodeG a c tag' text))) -> NodeG a c tag text -> NodeG a c tag' text Source #

mapAllTags :: (tag -> tag') -> NodeG a c tag text -> NodeG a c tag' text Source #

mapNodeContainer :: List c' => (forall a0. c a0 -> ItemM c (c' a0)) -> NodeG a c tag text -> ItemM c (NodeG a c' tag text) Source #

mkText :: text -> NodeG a c tag text Source #

(NFData tag, NFData text, NFData a) => NFData (NodeG a [] tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended Methods rnf :: NodeG a [] tag text -> () Source #
(Show tag, Show text, Show a) => Show (NodeG a [] tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended Methods showsPrec :: Int -> NodeG a [] tag text -> ShowS Source # show :: NodeG a [] tag text -> String Source # showList :: [NodeG a [] tag text] -> ShowS Source #
(Eq tag, Eq text, Eq a) => Eq (NodeG a [] tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended Methods (==) :: NodeG a [] tag text -> NodeG a [] tag text -> Bool Source # (/=) :: NodeG a [] tag text -> NodeG a [] tag text -> Bool Source #
type ListOf (NodeG a c tag text) Source # |
Instance details Defined in Text.XML.Expat.Extended type ListOf (NodeG a c tag text) = c (NodeG a c tag text)

type UDocument a text = Document a text text Source #

Type alias for an extended document with unqualified tag names where tag and text are the same string type

type LDocument tag text = Document XMLParseLocation tag text Source #

Type alias for an extended document, annotated with parse location

type ULDocument text = Document XMLParseLocation text text Source #

Type alias for an extended document with unqualified tag names where tag and text are the same string type, annotated with parse location

type UNode a text = Node a text text Source #

Type alias for an extended node with unqualified tag names where tag and text are the same string type

type LNode tag text = Node XMLParseLocation tag text Source #

Type alias for an extended node, annotated with parse location

type ULNode text = LNode text text Source #

Type alias for an extended node with unqualified tag names where tag and text are the same string type, annotated with parse location

# Generic document/node manipulation

module Text.XML.Expat.Internal.DocumentClass

module Text.XML.Expat.Internal.NodeClass

# Annotation-specific

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.

mapAnnotation :: (a -> b) -> Node a tag text -> Node b tag text Source #

Modify this node's annotation and all its children recursively if it's an element, otherwise no-op.

mapDocumentAnnotation :: (a -> b) -> Document a tag text -> Document b tag text Source #

Modify the annotation of every node in the document recursively.

# Qualified nodes

type QDocument a text = Document a (QName text) text Source #

Type alias for an extended document where qualified names are used for tags

type QLDocument text = Document XMLParseLocation (QName text) text Source #

Type alias for an extended document where qualified names are used for tags, annotated with parse location

type QNode a text = Node a (QName text) text Source #

Type alias for an extended node where qualified names are used for tags

type QLNode text = LNode (QName text) text Source #

Type alias for an extended node where qualified names are used for tags, annotated with parse location

module Text.XML.Expat.Internal.Qualified

# Namespaced nodes

type NDocument a text = Document a (NName text) text Source #

Type alias for an extended document where namespaced names are used for tags

type NLDocument text = Document XMLParseLocation (NName text) text Source #

Type alias for an extended document where namespaced names are used for tags, annotated with parse location

type NNode a text = Node a (NName text) text Source #

Type alias for an extended node where namespaced names are used for tags

type NLNode text = LNode (NName text) text Source #

Type alias for an extended 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 |

Fields

- overrideEncoding :: Maybe Encoding

  The encoding parameter, if provided, overrides the document's encoding declaration.

- entityDecoder :: Maybe (tag -> Maybe text)

  If provided, entity references (i.e. `&nbsp;` and friends) will be decoded into text using the supplied lookup function

defaultParseOptions :: ParseOptions tag text Source #

data Encoding Source #

Constructors

ASCII |
UTF8 |
UTF16 |
ISO88591 |

parse Source #

Arguments

:: (GenericXMLString tag, GenericXMLString text) |
=> ParseOptions tag text | Parse options
-> ByteString | Input text (a lazy ByteString)
-> (LDocument 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 #

Arguments

:: (GenericXMLString tag, GenericXMLString text) |
=> ParseOptions tag text | Parse options
-> ByteString | Input text (a strict ByteString)
-> Either XMLParseError (LDocument 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 |

#### Instances

Instances details

NFData XMLParseError Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods rnf :: XMLParseError -> () Source #
Show XMLParseError Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods showsPrec :: Int -> XMLParseError -> ShowS Source # show :: XMLParseError -> String Source # showList :: [XMLParseError] -> ShowS Source #
Eq XMLParseError Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods (==) :: XMLParseError -> XMLParseError -> Bool Source # (/=) :: XMLParseError -> XMLParseError -> Bool Source #

data XMLParseLocation Source #

Specifies a location of an event within the input text

Constructors

XMLParseLocation |

Fields

- 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

Instances details

NFData XMLParseLocation Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods rnf :: XMLParseLocation -> () Source #
Show XMLParseLocation Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods showsPrec :: Int -> XMLParseLocation -> ShowS Source # show :: XMLParseLocation -> String Source # showList :: [XMLParseLocation] -> ShowS Source #
Eq XMLParseLocation Source # |
Instance details Defined in Text.XML.Expat.Internal.IO Methods (==) :: XMLParseLocation -> XMLParseLocation -> Bool Source # (/=) :: XMLParseLocation -> XMLParseLocation -> Bool Source #

# Variant that throws exceptions

parseThrowing Source #

Arguments

:: (GenericXMLString tag, GenericXMLString text) |
=> ParseOptions tag text | Parse options
-> ByteString | Input text (a lazy ByteString)
-> LDocument 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 |

#### Instances

Instances details

Exception XMLParseException Source # |
Instance details Defined in Text.XML.Expat.SAX Methods toException :: XMLParseException -> SomeException Source # fromException :: SomeException -> Maybe XMLParseException Source # displayException :: XMLParseException -> String Source # backtraceDesired :: XMLParseException -> Bool Source #
Show XMLParseException Source # |
Instance details Defined in Text.XML.Expat.SAX Methods showsPrec :: Int -> XMLParseException -> ShowS Source # show :: XMLParseException -> String Source # showList :: [XMLParseException] -> ShowS Source #
Eq XMLParseException Source # |
Instance details Defined in Text.XML.Expat.SAX Methods (==) :: XMLParseException -> XMLParseException -> Bool Source # (/=) :: XMLParseException -> XMLParseException -> Bool Source #

# Convert from SAX

saxToTree :: (GenericXMLString tag, Monoid text) => [(SAXEvent tag text, a)] -> (Document 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 where Source #

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 -> Bool Source #

gxToString :: s -> String Source #

gxFromString :: String -> s Source #

gxFromChar :: Char -> s Source #

gxHead :: s -> Char Source #

gxTail :: s -> s Source #

gxBreakOn :: Char -> s -> (s, s) Source #

gxFromByteString :: ByteString -> s Source #

gxToByteString :: s -> ByteString Source #

#### Instances

Instances details

GenericXMLString ByteString Source # |

Instance details

Defined in Text.XML.Expat.SAX

Methods

gxNullString :: ByteString -> Bool Source #

gxToString :: ByteString -> String Source #

gxFromString :: String -> ByteString Source #

gxFromChar :: Char -> ByteString Source #

gxHead :: ByteString -> Char Source #

gxTail :: ByteString -> ByteString Source #

gxBreakOn :: Char -> ByteString -> (ByteString, ByteString) Source #

gxFromByteString :: ByteString -> ByteString Source #

gxToByteString :: ByteString -> ByteString Source #

GenericXMLString Text Source # |

Instance details

Defined in Text.XML.Expat.SAX

Methods

gxNullString :: Text -> Bool Source #

gxToString :: Text -> String Source #

gxFromString :: String -> Text Source #

gxFromChar :: Char -> Text Source #

gxHead :: Text -> Char Source #

gxTail :: Text -> Text Source #

gxBreakOn :: Char -> Text -> (Text, Text) Source #

gxFromByteString :: ByteString -> Text Source #

gxToByteString :: Text -> ByteString Source #

GenericXMLString String Source # |

Instance details

Defined in Text.XML.Expat.SAX

Methods

gxNullString :: String -> Bool Source #

gxToString :: String -> String Source #

gxFromString :: String -> String Source #

gxFromChar :: Char -> String Source #

gxHead :: String -> Char Source #

gxTail :: String -> String Source #

gxBreakOn :: Char -> String -> (String, String) Source #

gxFromByteString :: ByteString -> String Source #

gxToByteString :: String -> ByteString Source #