hexpat-0.19.10: XML parser/formatter based on expat

Safe HaskellSafe-Infered

Text.XML.Expat.Cursor

Contents

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

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.

Constructors

Cur 

Fields

current :: n c tag text

The 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 text

The contexts of the parent elements of this location.

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 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.

data Tag tag text Source

Constructors

Tag 

Fields

tagName :: tag
 
tagAttribs :: Attributes tag text
 

Instances

(Show tag, Show text) => Show (Tag tag text) 

getTag :: Node tag text -> Tag tag textSource

fromTag :: MkElementClass n c => Tag tag text -> c (n c tag text) -> n c tag textSource

Conversions

fromTree :: List c => n c tag text -> CursorG n c tag textSource

A cursor for the given content.

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

isRoot :: CursorG n c tag text -> BoolSource

Are we at the top of the document?

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?

isChild :: CursorG n c tag text -> BoolSource

Do we have a parent?

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.