hexpat-0.19.5: XML parser/formatter based on expatContentsIndex
Text.XML.Expat.Cursor
Contents
Types
Conversions
Moving around
Searching
Node classification
Updates
Inserting content
Removing content
Description

This module ported from Text.XML.Light.Cursor

XML cursors for working XML content withing the context of an XML document. This implementation is based on the general tree zipper written by Krasimir Angelov and Iavor S. Diatchki.

With the exception of modifyContentM, then M-suffixed functions are for use with monadic node types, as used when dealing with chunked I/O with the hexpat-iteratee package. In the more common pure case, you wouldn't need these *M functions.

Synopsis
type Cursor tag text = CursorG NodeG [] tag text
data CursorG n c tag text = Cur {
current :: n c tag text
lefts :: c (n c tag text)
rights :: c (n c tag text)
parents :: PathG n c tag text
}
type Path tag text = PathG NodeG [] tag text
type PathG n c tag text = [(c (n c tag text), Tag tag text, c (n c tag text))]
data Tag tag text = Tag {
tagName :: tag
tagAttribs :: Attributes tag text
}
getTag :: Node tag text -> Tag tag text
fromTag :: MkElementClass n c => Tag tag text -> c (n c tag text) -> n c tag text
fromTree :: List c => n c tag text -> CursorG n c tag text
fromForest :: NodeClass n [] => [n [] tag text] -> Maybe (CursorG n [] tag text)
toForest :: MkElementClass n c => CursorG n c tag text -> c (n c tag text)
toTree :: MkElementClass n c => CursorG n c tag text -> n c tag text
parent :: MkElementClass n c => CursorG n c tag text -> Maybe (CursorG n c tag text)
root :: MkElementClass n c => CursorG n c tag text -> CursorG n c tag text
getChild :: (NodeClass n [], Monoid tag) => Int -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
getChildM :: (NodeClass n c, Monoid tag) => Int -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
firstChild :: (NodeClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
firstChildM :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
lastChild :: (NodeClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
lastChildM :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
left :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
leftM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
right :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
rightM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
nextDF :: (MkElementClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
nextDFM :: (MkElementClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
findChild :: (NodeClass n [], Monoid tag) => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
findLeft :: NodeClass n [] => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
findRight :: (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
findRec :: (MkElementClass n [], Monoid tag) => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
findRecM :: (MkElementClass n c, Monoid tag) => (CursorG n c tag text -> ItemM c Bool) -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
isRoot :: CursorG n c tag text -> Bool
isFirst :: CursorG n [] tag text -> Bool
isFirstM :: List c => CursorG n c tag text -> ItemM c Bool
isLast :: CursorG n [] tag text -> Bool
isLastM :: List c => CursorG n c tag text -> ItemM c Bool
isLeaf :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> Bool
isChild :: CursorG n c tag text -> Bool
hasChildren :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> Bool
getNodeIndex :: CursorG n [] tag text -> Int
setContent :: n c tag text -> CursorG n c tag text -> CursorG n c tag text
modifyContent :: (n c tag text -> n c tag text) -> CursorG n c tag text -> CursorG n c tag text
modifyContentList :: NodeClass n [] => (n [] tag text -> [n [] tag text]) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
modifyContentListM :: NodeClass n c => (n c tag text -> c (n c tag text)) -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
modifyContentM :: Monad m => (n [] tag text -> m (n [] tag text)) -> CursorG n [] tag text -> m (CursorG n [] tag text)
insertLeft :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
insertRight :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
insertManyLeft :: List c => c (n c tag text) -> CursorG n c tag text -> CursorG n c tag text
insertManyRight :: List c => c (n c tag text) -> CursorG n c tag text -> CursorG n c tag text
insertFirstChild :: NodeClass n c => n c tag text -> CursorG n c tag text -> Maybe (CursorG n c tag text)
insertLastChild :: NodeClass n c => n c tag text -> CursorG n c tag text -> Maybe (CursorG n c tag text)
insertManyFirstChild :: NodeClass n c => c (n c tag text) -> CursorG n c tag text -> Maybe (CursorG n c tag text)
insertManyLastChild :: NodeClass n c => c (n c tag text) -> CursorG n c tag text -> Maybe (CursorG n c tag text)
insertGoLeft :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
insertGoRight :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
removeLeft :: CursorG n [] tag text -> Maybe (n [] tag text, CursorG n [] tag text)
removeLeftM :: List c => CursorG n c tag text -> ItemM c (Maybe (n c tag text, CursorG n c tag text))
removeRight :: CursorG n [] tag text -> Maybe (n [] tag text, CursorG n [] tag text)
removeRightM :: List c => CursorG n c tag text -> ItemM c (Maybe (n c tag text, CursorG n c tag text))
removeGoLeft :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
removeGoLeftM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
removeGoRight :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
removeGoRightM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
removeGoUp :: MkElementClass n c => CursorG n c tag text -> Maybe (CursorG n c tag text)
Types
type Cursor tag text = CursorG NodeG [] tag text
A cursor specific to Text.XML.Expat.Tree.Node trees.
data CursorG n c tag text
Generalized cursor: The position of a piece of content in an XML document. n is the Node type and c is the list type, which would usually be [], except when you're using chunked I/O.
Constructors
Cur
current :: n c tag textThe currently selected content.
lefts :: c (n c tag text)Siblings on the left, closest first.
rights :: c (n c tag text)Siblings on the right, closest first.
parents :: PathG n c tag textThe contexts of the parent elements of this location.
show/hide Instances
(Show (n c tag text), Show (c (n c tag text)), Show tag, Show text) => Show (CursorG n c tag text)
type Path tag text = PathG NodeG [] tag text
A path specific to Text.XML.Expat.Tree.Node trees.
type PathG n c tag text = [(c (n c tag text), Tag tag text, c (n c tag text))]
Generalized path within an XML document.
data Tag tag text
Constructors
Tag
tagName :: tag
tagAttribs :: Attributes tag text
show/hide Instances
(Show tag, Show text) => Show (Tag tag text)
getTag :: Node tag text -> Tag tag text
fromTag :: MkElementClass n c => Tag tag text -> c (n c tag text) -> n c tag text
Conversions
fromTree :: List c => n c tag text -> CursorG n c tag text
A cursor for the given content.
fromForest :: NodeClass n [] => [n [] tag text] -> Maybe (CursorG n [] tag text)
The location of the first tree in a forest - pure version.
toForest :: MkElementClass n c => CursorG n c tag text -> c (n c tag text)
Computes the forest containing this location.
toTree :: MkElementClass n c => CursorG n c tag text -> n c tag text
Computes the tree containing this location.
Moving around
parent :: MkElementClass n c => CursorG n c tag text -> Maybe (CursorG n c tag text)
The parent of the given location.
root :: MkElementClass n c => CursorG n c tag text -> CursorG n c tag text
The top-most parent of the given location.
getChild :: (NodeClass n [], Monoid tag) => Int -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The child with the given index (starting from 0). - pure version.
getChildM :: (NodeClass n c, Monoid tag) => Int -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The child with the given index (starting from 0) - used for monadic node types.
firstChild :: (NodeClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The first child of the given location - pure version.
firstChildM :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The first child of the given location - used for monadic node types.
lastChild :: (NodeClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The last child of the given location - pure version.
lastChildM :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The last child of the given location - used for monadic node types.
left :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The left sibling of the given location - pure version.
leftM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The left sibling of the given location - used for monadic node types.
right :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The right sibling of the given location - pure version.
rightM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The right sibling of the given location - used for monadic node types.
nextDF :: (MkElementClass n [], Monoid tag) => CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The next position in a left-to-right depth-first traversal of a document: either the first child, right sibling, or the right sibling of a parent that has one. Pure version.
nextDFM :: (MkElementClass n c, Monoid tag) => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
The next position in a left-to-right depth-first traversal of a document: either the first child, right sibling, or the right sibling of a parent that has one. Used for monadic node types.
Searching
findChild :: (NodeClass n [], Monoid tag) => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
The first child that satisfies a predicate - pure version.
findLeft :: NodeClass n [] => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Find the next left sibling that satisfies a predicate.
findRight :: (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Find the next right sibling that satisfies a predicate - pure version.
findRec :: (MkElementClass n [], Monoid tag) => (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Perform a depth first search for a descendant that satisfies the given predicate. Pure version.
findRecM :: (MkElementClass n c, Monoid tag) => (CursorG n c tag text -> ItemM c Bool) -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
Perform a depth first search for a descendant that satisfies the given predicate. Used for monadic node types.
Node classification
isRoot :: CursorG n c tag text -> Bool
Are we at the top of the document?
isFirst :: CursorG n [] tag text -> Bool
Are we at the left end of the the document? (Pure version.)
isFirstM :: List c => CursorG n c tag text -> ItemM c Bool
Are we at the left end of the the document? (Used for monadic node types.)
isLast :: CursorG n [] tag text -> Bool
Are we at the right end of the document? (Pure version.)
isLastM :: List c => CursorG n c tag text -> ItemM c Bool
Are we at the right end of the document? (Used for monadic node types.)
isLeaf :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> Bool
Are we at the bottom of the document?
isChild :: CursorG n c tag text -> Bool
Do we have a parent?
hasChildren :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> Bool
Do we have children?
getNodeIndex :: CursorG n [] tag text -> Int
Get the node index inside the sequence of children - pure version.
Updates
setContent :: n c tag text -> CursorG n c tag text -> CursorG n c tag text
Change the current content.
modifyContent :: (n c tag text -> n c tag text) -> CursorG n c tag text -> CursorG n c tag text
Modify the current content.
modifyContentList :: NodeClass n [] => (n [] tag text -> [n [] tag text]) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Modify the current content - pure version.
modifyContentListM :: NodeClass n c => (n c tag text -> c (n c tag text)) -> CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
Modify the current content - used for monadic node types.
modifyContentM :: Monad m => (n [] tag text -> m (n [] tag text)) -> CursorG n [] tag text -> m (CursorG n [] tag text)
Modify the current content, allowing for an effect.
Inserting content
insertLeft :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
Insert content to the left of the current position.
insertRight :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
Insert content to the right of the current position.
insertManyLeft :: List c => c (n c tag text) -> CursorG n c tag text -> CursorG n c tag text
Insert content to the left of the current position.
insertManyRight :: List c => c (n c tag text) -> CursorG n c tag text -> CursorG n c tag text
Insert content to the right of the current position.
insertFirstChild :: NodeClass n c => n c tag text -> CursorG n c tag text -> Maybe (CursorG n c tag text)
Insert content as the first child of the current position.
insertLastChild :: NodeClass n c => n c tag text -> CursorG n c tag text -> Maybe (CursorG n c tag text)
Insert content as the first child of the current position.
insertManyFirstChild :: NodeClass n c => c (n c tag text) -> CursorG n c tag text -> Maybe (CursorG n c tag text)
Insert content as the first child of the current position.
insertManyLastChild :: NodeClass n c => c (n c tag text) -> CursorG n c tag text -> Maybe (CursorG n c tag text)
Insert content as the first child of the current position.
insertGoLeft :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
Insert content to the left of the current position. The new content becomes the current position.
insertGoRight :: List c => n c tag text -> CursorG n c tag text -> CursorG n c tag text
Insert content to the right of the current position. The new content becomes the current position.
Removing content
removeLeft :: CursorG n [] tag text -> Maybe (n [] tag text, CursorG n [] tag text)
Remove the content on the left of the current position, if any - pure version.
removeLeftM :: List c => CursorG n c tag text -> ItemM c (Maybe (n c tag text, CursorG n c tag text))
Remove the content on the left of the current position, if any - used for monadic node types.
removeRight :: CursorG n [] tag text -> Maybe (n [] tag text, CursorG n [] tag text)
Remove the content on the right of the current position, if any - pure version.
removeRightM :: List c => CursorG n c tag text -> ItemM c (Maybe (n c tag text, CursorG n c tag text))
Remove the content on the left of the current position, if any - used for monadic node types.
removeGoLeft :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Remove the current element. The new position is the one on the left. Pure version.
removeGoLeftM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
Remove the current element. The new position is the one on the left. Pure version.
removeGoRight :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)
Remove the current element. The new position is the one on the right. Pure version.
removeGoRightM :: List c => CursorG n c tag text -> ItemM c (Maybe (CursorG n c tag text))
Remove the current element. The new position is the one on the right. Used for monadic node types.
removeGoUp :: MkElementClass n c => CursorG n c tag text -> Maybe (CursorG n c tag text)
Remove the current element. The new position is the parent of the old position.
Produced by Haddock version 2.7.2