For example, I have a div containing a few ps and others, and I want to map the ps with show.
defShow :: NTree XNode -> String
defShow (NTree (XTag div' _) contents)
| show div' == "div" = intercalate "\n" $ map defShow contents
defShow p@(NTree (XTag p' []) _)
| show p' == "p" = show p
defShow x = error $ show x
But with testing data as following, this does not work. I mean the whole node, not just the p node.
NTree (XTag "div" [NTree (XAttr "class") [NTree (XText "refsect2") []]])
[ NTree (XText "\n") []
, NTree (XTag "p" []) [SOME_TEXT_NODE] ]
Don't use
showin the logic of your program. You can usemkNameto convert aStringto aQName.