I'm putting in a lot of time trying to figure out how to use HXT. I keep coming against examples using deep
. What does deep
do?
For example, this code has the following:
atTag tag = deep (isElem >>> hasName tag)
Another example:
-- case-insensitive tag matching
atTagCase tag = deep (isElem >>> hasNameWith ((== tag') . upper . localPart))
where tag' = upper tag
upper = map toUpper
http://hackage.haskell.org/packages/archive/hxt/latest/doc/html/Control-Arrow-ArrowTree.html#v:deep
deep :: Tree t => a (t b) c -> a (t b) cSource
recursively searches a whole tree for subtrees, for which a predicate holds. The search is performed top down. When a tree is found, this becomes an element of the result list. The tree found is not further examined for any subtress, for which the predicate also could hold. See
multi
for this kind of search.example:
deep isHtmlTable
selects all top level table elements in a document (with an appropriate definition forisHtmlTable
) but no tables occuring within a table cell.
You could find the documentation given a function name or type signature with Hoogle or Hayoo!
Basically, if the XML tree is like
<p>
<strong id="a">
<em id="b">
<strong id="c">
foo
</strong>
</em>
</strong>
<ins id="d">
<strong id="e">
bar
</strong>
<em id="f">
baz
</em>
</ins>
</p>
deep (isElem >>> hasName "strong") tree
will return a list for
<strong id="a">
<strong id="e">
because we can find these two <strong>
s when walking into the tree, while (isElem >>> hasName tag) tree
will return an empty list because the root of the tree is a <p>
, not a <strong>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With