开发者

HXT -- what is "deep"?

I'm putting in a lot of time t开发者_运维问答rying 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 for isHtmlTable) 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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜