taggy-0.1.1: Efficient and simple HTML/XML parsing library

Stabilityexperimental
Maintaineralpmestan@gmail.com
Safe HaskellNone

Text.Taggy.Combinators

Description

Many useful combinators for querying Elements of a DOM tree.

Synopsis

Documentation

hasName :: Element -> Text -> BoolSource

Does the given Element have the given name?

hasAttr :: Element -> AttrName -> BoolSource

Does the given element have an attribute with the given name (or key)

getAttr :: Element -> AttrName -> Maybe AttrValueSource

Get the value for the given attribute name in the given Element. Returns Nothing if the provided Element doesn't have an attribute with that name.

innerText :: Element -> TextSource

Get all the bits of raw text present everywhere below the given Element in the DOM tree.

(//) :: Element -> (Element -> Bool) -> [Element]Source

Filter an element and its children to those satisfying a given predicate.

(/&) :: Element -> [Element -> Bool] -> [Element]Source

Given a sequence of predicates, filter an element and its children, selecting only those subtrees who match the provided predicate for each point.

>>> let element = (\(NodeElement e) -> e) . head . domify . taggyWith False $ "<html>foo<bar class=\"el\">baz</bar><qux class=\"el\"><quux></quux></qux></html>"
>>> element /& [const False]
[]
>>> element /& [flip hasAttr "class", flip hasName "quux"]
[Element "quux" "" ""]

(/*) :: Element -> [Element -> Bool] -> [Element]Source

Filter from all subtrees (including the one with the target as its root), those matching the given sequence of predicates.

trees :: Element -> [Element]Source

Extracts all subtrees of its target, including the target.

subtrees :: Element -> [Element]Source

Extracts all subtrees of its target, excluding the target.