xmlhtml-0.2.5.2: XML parser and renderer with HTML 5 quirks mode

Safe HaskellNone
LanguageHaskell98

Text.XmlHtml.Cursor

Contents

Description

A zipper for navigating and modifying XML trees. This is nearly the same exposed interface as the xml package in Text.XML.Light.Cursor, with modifications as needed to adapt to different types.

Synopsis

Cursor type

data Cursor #

A zipper for XML document forests.

Instances

Eq Cursor # 

Methods

(==) :: Cursor -> Cursor -> Bool #

(/=) :: Cursor -> Cursor -> Bool #

Conversion to and from cursors

fromNode :: Node -> Cursor #

Builds a Cursor for navigating a tree. That is, a forest with a single root Node.

fromNodes :: [Node] -> Maybe Cursor #

Builds a Cursor for navigating a forest with the given list of roots. The cursor is initially positioned at the left-most node. Gives Nothing if the list is empty.

topNode :: Cursor -> Node #

Retrieves the root node containing the current cursor position.

topNodes :: Cursor -> [Node] #

Retrieves the entire forest of Nodes corresponding to a Cursor.

current :: Cursor -> Node #

Retrieves the current node of a Cursor

siblings :: Cursor -> [Node] #

Retrieves a list of the Nodes at the same level as the current position of a cursor, including the current node.

Cursor navigation

parent :: Cursor -> Maybe Cursor #

Navigates a Cursor to its parent in the document.

root :: Cursor -> Cursor #

Navigates a Cursor up through parents to reach the root level.

getChild :: Int -> Cursor -> Maybe Cursor #

Navigates a Cursor down to the indicated child index.

firstChild :: Cursor -> Maybe Cursor #

Navigates a Cursor down to its first child.

lastChild :: Cursor -> Maybe Cursor #

Navigates a Cursor down to its last child.

left :: Cursor -> Maybe Cursor #

Moves a Cursor to its left sibling.

right :: Cursor -> Maybe Cursor #

Moves a Cursor to its right sibling.

nextDF :: Cursor -> Maybe Cursor #

Moves a Cursor to the next node encountered in a depth-first search. If it has children, this is equivalent to firstChild. Otherwise, if it has a right sibling, then this is equivalent to right. Otherwise, the cursor moves to the first right sibling of one of its parents.

Search

findChild :: (Cursor -> Bool) -> Cursor -> Maybe Cursor #

Navigates a Cursor to the first child that matches the predicate.

findLeft :: (Cursor -> Bool) -> Cursor -> Maybe Cursor #

Navigates a Cursor to the nearest left sibling that matches a predicate.

findRight :: (Cursor -> Bool) -> Cursor -> Maybe Cursor #

Navigates a Cursor to the nearest right sibling that matches a predicate.

findRec :: (Cursor -> Bool) -> Cursor -> Maybe Cursor #

Does a depth-first search for a descendant matching the predicate. This can match the current cursor position.

Node classification

isRoot :: Cursor -> Bool #

Determines if the Cursor is at a root node.

isFirst :: Cursor -> Bool #

Determines if the Cursor is at a first child.

isLast :: Cursor -> Bool #

Determines if the Cursor is at a last child.

isLeaf :: Cursor -> Bool #

Determines if the Cursor is at a leaf node.

isChild :: Cursor -> Bool #

Determines if the Cursor is at a child node (i.e., if it has a parent).

hasChildren :: Cursor -> Bool #

Determines if the Cursor is at a non-leaf node (i.e., if it has children).

getNodeIndex :: Cursor -> Int #

Gets the index of the Cursor among its siblings.

Updates

setNode :: Node -> Cursor -> Cursor #

Replaces the current node.

modifyNode :: (Node -> Node) -> Cursor -> Cursor #

Modifies the current node by applying a function.

modifyNodeM :: Functor m => (Node -> m Node) -> Cursor -> m Cursor #

Modifies the current node by applying an action in some functor.

Insertions

insertLeft :: Node -> Cursor -> Cursor #

Inserts a new Node to the left of the current position.

insertRight :: Node -> Cursor -> Cursor #

Inserts a new Node to the right of the current position.

insertManyLeft :: [Node] -> Cursor -> Cursor #

Inserts a list of new Nodes to the left of the current position.

insertManyRight :: [Node] -> Cursor -> Cursor #

Inserts a list of new Nodes to the right of the current position.

insertFirstChild :: Node -> Cursor -> Maybe Cursor #

Inserts a Node as the first child of the current element.

insertLastChild :: Node -> Cursor -> Maybe Cursor #

Inserts a Node as the last child of the current element.

insertManyFirstChild :: [Node] -> Cursor -> Maybe Cursor #

Inserts a list of Nodes as the first children of the current element.

insertManyLastChild :: [Node] -> Cursor -> Maybe Cursor #

Inserts a list of Nodes as the last children of the current element.

insertGoLeft :: Node -> Cursor -> Cursor #

Inserts a new Node to the left of the current position, and moves left to the new node.

insertGoRight :: Node -> Cursor -> Cursor #

Inserts a new Node to the right of the current position, and moves right to the new node.

Deletions

removeLeft :: Cursor -> Maybe (Node, Cursor) #

Removes the Node to the left of the current position, if any.

removeRight :: Cursor -> Maybe (Node, Cursor) #

Removes the Node to the right of the current position, if any.

removeGoLeft :: Cursor -> Maybe Cursor #

Removes the current Node, and moves the Cursor to its left sibling, if any.

removeGoRight :: Cursor -> Maybe Cursor #

Removes the current Node, and moves the Cursor to its right sibling, if any.

removeGoUp :: Cursor -> Maybe Cursor #

Removes the current Node, and moves the Cursor to its parent, if any.