Text.XML.Enumerator.Cursor
- class Boolean a where
- type Axis = Cursor -> [Cursor]
- data Cursor
- fromDocument :: Document -> Cursor
- fromNode :: Node -> Cursor
- cut :: Cursor -> Cursor
- parent :: Axis
- precedingSibling :: Axis
- followingSibling :: Axis
- child :: Cursor -> [Cursor]
- node :: Cursor -> Node
- preceding :: Axis
- following :: Axis
- ancestor :: Axis
- descendant :: Axis
- orSelf :: Axis -> Axis
- (&/) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]
- (&//) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]
- (&.//) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]
- ($|) :: Cursor -> (Cursor -> [a]) -> [a]
- ($/) :: Cursor -> (Cursor -> [a]) -> [a]
- ($//) :: Cursor -> (Cursor -> [a]) -> [a]
- ($.//) :: Cursor -> (Cursor -> [a]) -> [a]
- check :: Boolean b => (Cursor -> b) -> Axis
- checkNode :: Boolean b => (Node -> b) -> Axis
- checkElement :: Boolean b => (Element -> b) -> Axis
- checkName :: Boolean b => (Name -> b) -> Axis
- anyElement :: Axis
- element :: Name -> Axis
- content :: Cursor -> [Text]
- attribute :: Name -> Cursor -> [Text]
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
Documentation
Something that can be used in a predicate check as a boolean.
type Axis = Cursor -> [Cursor]Source
The type of an Axis that returns a list of Cursors. They are roughly modeled after http://www.w3.org/TR/xpath/#axes.
Axes can be composed with >=>
, where e.g. f >=> g
means that on all results of
the f
axis, the g
axis will be applied, and all results joined together.
Because Axis is just a type synonym for Cursor -> [Cursor]
, it is possible to use
other standard functions like >>=
or concatMap
similarly.
The operators &/
, &//
and &.//
can be used to combine axes so that the second
axis works on the children, descendants, respectively the context node as well as its
descendants of the results of the first axis.
The operators $|
, $/
, $//
and $.//
can be used to apply an axis (right-hand side)
to a cursor so that it is applied on the cursor itself, its children, its descendants,
respectively itself and its descendants.
Note that many of these operators also work on generalised Axes that can return lists of something other than Cursors, for example Content elements.
A cursor: contains an XML Node
and pointers to its children, ancestors and siblings.
fromDocument :: Document -> CursorSource
Cut a cursor off from its parent. The idea is to allow restricting the scope of queries on it.
The parent axis. As described in XPath: the parent axis contains the parent of the context node, if there is one.
precedingSibling :: AxisSource
The preceding-sibling axis. XPath: the preceding-sibling axis contains all the preceding siblings of the context node [...].
followingSibling :: AxisSource
The following-sibling axis. XPath: the following-sibling axis contains all the following siblings of the context node [...].
child :: Cursor -> [Cursor]Source
The child axis. XPath: the child axis contains the children of the context node.
The preceding axis. XPath: the preceding axis contains all nodes in the same document as the context node that are before the context node in document order, excluding any ancestors and excluding attribute nodes and namespace nodes.
The following axis. XPath: the following axis contains all nodes in the same document as the context node that are after the context node in document order, excluding any descendants and excluding attribute nodes and namespace nodes.
The ancestor axis. XPath: the ancestor axis contains the ancestors of the context node; the ancestors of the context node consist of the parent of context node and the parent's parent and so on; thus, the ancestor axis will always include the root node, unless the context node is the root node.
The descendant axis. XPath: the descendant axis contains the descendants of the context node; a descendant is a child or a child of a child and so on; thus the descendant axis never contains attribute or namespace nodes.
Modify an axis by adding the context node itself as the first element of the result list.
(&/) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]Source
Combine two axes so that the second works on the children of the results of the first.
(&//) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]Source
Combine two axes so that the second works on the descendants of the results of the first.
(&.//) :: Axis -> (Cursor -> [a]) -> Cursor -> [a]Source
Combine two axes so that the second works on both the result nodes, and their descendants.
($.//) :: Cursor -> (Cursor -> [a]) -> [a]Source
Apply an axis to a Cursor
as well as its descendants.
checkElement :: Boolean b => (Element -> b) -> AxisSource
Filter elements that don't pass a check, and remove all non-elements.
checkName :: Boolean b => (Name -> b) -> AxisSource
Filter elements that don't pass a name check, and remove all non-elements.
Remove all non-elements. Compare roughly to XPath: A node test * is true for any node of the principal node type. For example, child::* will select all element children of the context node [...].
Select only those elements with a matching tag name. XPath: A node test that is a QName is true if and only if the type of the node (see [5 Data Model]) is the principal node type and has an expanded-name equal to the expanded-name specified by the QName.
content :: Cursor -> [Text]Source
Select only text nodes, and directly give the Content
values. XPath:
The node test text() is true for any text node.
Note that this is not strictly an Axis
, but will work with most combinators.
attribute :: Name -> Cursor -> [Text]Source
Select attributes on the current element (or nothing if it is not an element). XPath: the attribute axis contains the attributes of the context node; the axis will be empty unless the context node is an element
Note that this is not strictly an Axis
, but will work with most combinators.
The return list of the generalised axis contains as elements lists of Content
elements, each full list representing an attribute value.