![]() The XML parser of the Haskell XML Toolbox uses this function internally. Having defined combinators and basic filters already, it shows how they can usefully be combined into a complex function for merging the internal and external DTD subset. Merging internal and external DTD subsetĪfter discussing the simple example for removing comments, this example will show a much more complex use of filters. The use of predefined combinators and filters makes it possible to program on a very high abstraction level.Ģ.5.2. The programmer does not have to worry about how to apply a filter to the whole tree and how to transform it. They define own control structures and hide processing of the XmlTree from the programmer. The functions isOfNode, none, when and applyBottomUp are already exported by the module XmlTree. This example shows very clearly how complex filters can be constructed out of simple ones. The result is a new tree where all comments have been removed. It uses the recursive transformation filter applyBottomUp, which applies the filter removeComment to the whole tree. The main filter removeAllComment is a filter for removing all comments from an XmlTree. Otherwise a list with the node is returned. If the predicate filter isXCmt is true, none returns an empty list. The filter removeComment combines the simple filter none and the above described filter isXCmt with the combinator when. The filter removeComment takes a node and returns an empty list if the node is a comment, otherwise a list with the passed node is returned. IsOfNode :: (node -> Bool) -> TFilter node The predicate function isXCmtNode uses pattern matching to figure out if a node is of type XCmt. The selection filter isOfNode takes the predicate function as a parameter and returns a list with the passed node if the predicate function returns true for this node. The predicate filter isXCmt itself bases on the basic selection filter isOfNode, which is exported by the module XmlTree, and the predicate function isXCmtNode. If the node is a comment, a list with this node is returned, otherwise the result is an empty list. It takes a node and checks if the node is of type XCmt. The function isXCmt is a predicate filter that detects comment nodes. The final filter will apply this filter to the whole tree and create a new tree from its results. Building on this filter a more complex one will be constructed that returns an empty list for comment nodes, but returns all other nodes. To implement this filter, a predicate function is needed first, which detects comment nodes. The result is a new tree without comment nodes. This filter returns an empty list for comment nodes, all other nodes are simply returned. ![]() Removing comments from an XmlTree is done by transforming the tree with a special filter. It illustrates, how a complex filter can be constructed by combining very simple ones. This example describes in depth the use of filters and combinators for removing comments from an XmlTree.
0 Comments
Leave a Reply. |