HXT - What is Deep?

I have been trying a lot to figure out how to use HXT. I continue to resort to 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 
+4
source share
1 answer

http://hackage.haskell.org/packages/archive/hxt/latest/doc/html/Control-Arrow-ArrowTree.html#v:deep

 deep :: Tree t => a (tb) c -> a (tb) cSource 

recursively searches for a whole tree for subtrees for which the predicate is executed. Search is performed from top to bottom. When a tree is found, it becomes an element of the result list. The found tree is not considered further for any subheading for which a predicate can also be saved. See multi for such a search.

example: deep isHtmlTable selects all the elements of a top-level table in a document (with the corresponding definition for isHtmlTable ), but tables are not found inside the table cell.

You can find documentation with function name or type 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> while walking in the tree, and (isElem >>> hasName tag) tree will return an empty list, because the root of the tree is <p> , not <strong>

+8
source

All Articles