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.
- type Cursor tag text = CursorG NodeG [] tag text
- data CursorG n c tag text = Cur {}
- 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 textSource
A cursor specific to Text.XML.Expat.Tree.Node
trees.
data CursorG n c tag text Source
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.
type Path tag text = PathG NodeG [] tag textSource
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))]Source
Generalized path within an XML document.
Tag | |
|
fromTag :: MkElementClass n c => Tag tag text -> c (n c tag text) -> n c tag textSource
Conversions
fromForest :: NodeClass n [] => [n [] tag text] -> Maybe (CursorG n [] tag text)Source
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)Source
Computes the forest containing this location.
toTree :: MkElementClass n c => CursorG n c tag text -> n c tag textSource
Computes the tree containing this location.
Moving around
parent :: MkElementClass n c => CursorG n c tag text -> Maybe (CursorG n c tag text)Source
The parent of the given location.
root :: MkElementClass n c => CursorG n c tag text -> CursorG n c tag textSource
The top-most parent of the given location.
getChild :: (NodeClass n [], Monoid tag) => Int -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)Source
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))Source
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)Source
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))Source
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)Source
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))Source
The last child of the given location - used for monadic node types.
left :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)Source
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))Source
The left sibling of the given location - used for monadic node types.
right :: CursorG n [] tag text -> Maybe (CursorG n [] tag text)Source
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))Source
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)Source
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))Source
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)Source
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)Source
Find the next left sibling that satisfies a predicate.
findRight :: (CursorG n [] tag text -> Bool) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)Source
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)Source
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))Source
Perform a depth first search for a descendant that satisfies the given predicate. Used for monadic node types.
Node classification
isFirst :: CursorG n [] tag text -> BoolSource
Are we at the left end of the the document? (Pure version.)
isFirstM :: List c => CursorG n c tag text -> ItemM c BoolSource
Are we at the left end of the the document? (Used for monadic node types.)
isLast :: CursorG n [] tag text -> BoolSource
Are we at the right end of the document? (Pure version.)
isLastM :: List c => CursorG n c tag text -> ItemM c BoolSource
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 -> BoolSource
Are we at the bottom of the document?
hasChildren :: (NodeClass n c, Monoid tag) => CursorG n c tag text -> BoolSource
Do we have children?
getNodeIndex :: CursorG n [] tag text -> IntSource
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 textSource
Change the current content.
modifyContent :: (n c tag text -> n c tag text) -> CursorG n c tag text -> CursorG n c tag textSource
Modify the current content.
modifyContentList :: NodeClass n [] => (n [] tag text -> [n [] tag text]) -> CursorG n [] tag text -> Maybe (CursorG n [] tag text)Source
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))Source
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)Source
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 textSource
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 textSource
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 textSource
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 textSource
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)Source
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)Source
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)Source
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)Source
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 textSource
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 textSource
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)Source
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))Source
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)Source
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))Source
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)Source
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))Source
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)Source
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))Source
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)Source
Remove the current element. The new position is the parent of the old position.