hexpat-0.11: wrapper for expat, the fast XML parserSource codeContentsIndex
Text.XML.Expat.Cursor
Contents
Conversions
Moving around
Searching
Node classification
Updates
Inserting content
Removing content
Description

This module ported from Text.XML.Light.Proc

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.

Synopsis
data Tag tag text = Tag {
tagName :: tag
tagAttribs :: Attributes tag text
}
getTag :: Node tag text -> Tag tag text
fromTag :: Tag tag text -> [Node tag text] -> Node tag text
data Cursor tag text = Cur {
current :: Node tag text
lefts :: [Node tag text]
rights :: [Node tag text]
parents :: Path tag text
}
type Path tag text = [([Node tag text], Tag tag text, [Node tag text])]
fromTree :: Node tag text -> Cursor tag text
fromForest :: [Node tag text] -> Maybe (Cursor tag text)
toForest :: Cursor tag text -> [Node tag text]
toTree :: Cursor tag text -> Node tag text
parent :: Cursor tag text -> Maybe (Cursor tag text)
root :: Cursor tag text -> Cursor tag text
getChild :: Int -> Cursor tag text -> Maybe (Cursor tag text)
firstChild :: Cursor tag text -> Maybe (Cursor tag text)
lastChild :: Cursor tag text -> Maybe (Cursor tag text)
left :: Cursor tag text -> Maybe (Cursor tag text)
right :: Cursor tag text -> Maybe (Cursor tag text)
nextDF :: Cursor tag text -> Maybe (Cursor tag text)
findChild :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)
findLeft :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)
findRight :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)
findRec :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)
isRoot :: Cursor tag text -> Bool
isFirst :: Cursor tag text -> Bool
isLast :: Cursor tag text -> Bool
isLeaf :: Cursor tag text -> Bool
isChild :: Cursor tag text -> Bool
hasChildren :: Cursor tag text -> Bool
getNodeIndex :: Cursor tag text -> Int
setContent :: Node tag text -> Cursor tag text -> Cursor tag text
modifyContent :: (Node tag text -> Node tag text) -> Cursor tag text -> Cursor tag text
modifyContentList :: (Node tag text -> [Node tag text]) -> Cursor tag text -> Maybe (Cursor tag text)
modifyContentM :: Monad m => (Node tag text -> m (Node tag text)) -> Cursor tag text -> m (Cursor tag text)
insertLeft :: Node tag text -> Cursor tag text -> Cursor tag text
insertRight :: Node tag text -> Cursor tag text -> Cursor tag text
insertManyLeft :: [Node tag text] -> Cursor tag text -> Cursor tag text
insertManyRight :: [Node tag text] -> Cursor tag text -> Cursor tag text
insertFirstChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text)
insertLastChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text)
insertManyFirstChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text)
insertManyLastChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text)
insertGoLeft :: Node tag text -> Cursor tag text -> Cursor tag text
insertGoRight :: Node tag text -> Cursor tag text -> Cursor tag text
removeLeft :: Cursor tag text -> Maybe (Node tag text, Cursor tag text)
removeRight :: Cursor tag text -> Maybe (Node tag text, Cursor tag text)
removeGoLeft :: Cursor tag text -> Maybe (Cursor tag text)
removeGoRight :: Cursor tag text -> Maybe (Cursor tag text)
removeGoUp :: Cursor tag text -> Maybe (Cursor tag text)
Documentation
data Tag tag text Source
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 textSource
fromTag :: Tag tag text -> [Node tag text] -> Node tag textSource
data Cursor tag text Source
The position of a piece of content in an XML document.
Constructors
Cur
current :: Node tag textThe currently selected content.
lefts :: [Node tag text]Siblings on the left, closest first.
rights :: [Node tag text]Siblings on the right, closest first.
parents :: Path tag textThe contexts of the parent elements of this location.
show/hide Instances
(Show tag, Show text) => Show (Cursor tag text)
type Path tag text = [([Node tag text], Tag tag text, [Node tag text])]Source
Conversions
fromTree :: Node tag text -> Cursor tag textSource
A cursor for the given content.
fromForest :: [Node tag text] -> Maybe (Cursor tag text)Source
The location of the first tree in a forest.
toForest :: Cursor tag text -> [Node tag text]Source
Computes the forest containing this location.
toTree :: Cursor tag text -> Node tag textSource
Computes the tree containing this location.
Moving around
parent :: Cursor tag text -> Maybe (Cursor tag text)Source
The parent of the given location.
root :: Cursor tag text -> Cursor tag textSource
The top-most parent of the given location.
getChild :: Int -> Cursor tag text -> Maybe (Cursor tag text)Source
The child with the given index (starting from 0).
firstChild :: Cursor tag text -> Maybe (Cursor tag text)Source
The first child of the given location.
lastChild :: Cursor tag text -> Maybe (Cursor tag text)Source
The last child of the given location.
left :: Cursor tag text -> Maybe (Cursor tag text)Source
The left sibling of the given location.
right :: Cursor tag text -> Maybe (Cursor tag text)Source
The right sibling of the given location.
nextDF :: Cursor tag text -> Maybe (Cursor 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.
Searching
findChild :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)Source
The first child that satisfies a predicate.
findLeft :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)Source
Find the next left sibling that satisfies a predicate.
findRight :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)Source
Find the next right sibling that satisfies a predicate.
findRec :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text)Source
Perform a depth first search for a descendant that satisfies the given predicate.
Node classification
isRoot :: Cursor tag text -> BoolSource
Are we at the top of the document?
isFirst :: Cursor tag text -> BoolSource
Are we at the left end of the the document?
isLast :: Cursor tag text -> BoolSource
Are we at the right end of the document?
isLeaf :: Cursor tag text -> BoolSource
Are we at the bottom of the document?
isChild :: Cursor tag text -> BoolSource
Do we have a parent?
hasChildren :: Cursor tag text -> BoolSource
Do we have children?
getNodeIndex :: Cursor tag text -> IntSource
Get the node index inside the sequence of children
Updates
setContent :: Node tag text -> Cursor tag text -> Cursor tag textSource
Change the current content.
modifyContent :: (Node tag text -> Node tag text) -> Cursor tag text -> Cursor tag textSource
Modify the current content.
modifyContentList :: (Node tag text -> [Node tag text]) -> Cursor tag text -> Maybe (Cursor tag text)Source
Modify the current content.
modifyContentM :: Monad m => (Node tag text -> m (Node tag text)) -> Cursor tag text -> m (Cursor tag text)Source
Modify the current content, allowing for an effect.
Inserting content
insertLeft :: Node tag text -> Cursor tag text -> Cursor tag textSource
Insert content to the left of the current position.
insertRight :: Node tag text -> Cursor tag text -> Cursor tag textSource
Insert content to the right of the current position.
insertManyLeft :: [Node tag text] -> Cursor tag text -> Cursor tag textSource
Insert content to the left of the current position.
insertManyRight :: [Node tag text] -> Cursor tag text -> Cursor tag textSource
Insert content to the right of the current position.
insertFirstChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text)Source
Insert content as the first child of the current position.
insertLastChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text)Source
Insert content as the first child of the current position.
insertManyFirstChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text)Source
Insert content as the first child of the current position.
insertManyLastChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text)Source
Insert content as the first child of the current position.
insertGoLeft :: Node tag text -> Cursor tag text -> Cursor tag textSource
Insert content to the left of the current position. The new content becomes the current position.
insertGoRight :: Node tag text -> Cursor tag text -> Cursor tag textSource
Insert content to the right of the current position. The new content becomes the current position.
Removing content
removeLeft :: Cursor tag text -> Maybe (Node tag text, Cursor tag text)Source
Remove the content on the left of the current position, if any.
removeRight :: Cursor tag text -> Maybe (Node tag text, Cursor tag text)Source
Remove the content on the right of the current position, if any.
removeGoLeft :: Cursor tag text -> Maybe (Cursor tag text)Source
Remove the current element. The new position is the one on the left.
removeGoRight :: Cursor tag text -> Maybe (Cursor tag text)Source
Remove the current element. The new position is the one on the right.
removeGoUp :: Cursor tag text -> Maybe (Cursor tag text)Source
Remove the current element. The new position is the parent of the old position.
Produced by Haddock version 2.6.0