From what I can tell, normal HXT seems to be more geared toward queries on XML moreso than XML AST refactoring. However, one of the HXT modules, Data.Tree.NTree.Zippers.TypeDefs
seems to have some machinery for diving into a document and doing local work, instead of the more global arrows. However, I can't seem to get anything to work. This is a follow-up post to my earlier HXT issue - all the code is the same, except now trans
is replacing this
.
Here is the entry point to my program:
start :: App -> IO [XmlTree]
start (App src dest) = runX $
readDocument [
--... some settings ...
]
src
>>>
trans
>>>
writeDocument [
--... some settings ...
]
dest
And here is the module where trans
is defined:
module Main.Internal where
import Data.Maybe (fromJust)
import Text.XML.HXT.DOM.XmlNode (mkText')
import Text.XML.HXT.Core hiding (addToTheRight)
import Data.Tree.NTree.Zipper.TypeDefs
trans :: IOSLA (XIOState s) XmlTree XmlTree
trans = arrL go
where
go :: XmlTree -> [XmlTree]
go x = [fromNTZipper . manip . toNTZipper $ x]
unList :: [a] -> a
unList [] = error "dun goofed!"
unList (x:_) = x
manip = fromJust . (addToTheRight $ mkText' "bar")
. fromJust . down
Finally, here is my input file:
<html>
<head>
<title>foo</title>
</head>
<body>
<h1>foo</h1>
</body>
</html>
and my output:
<?xml version="1.0" encoding="US-ASCII"?>
<html>
<head>
<title>foo</title>
</head>
<body>
<h1>foo</h1>
</body>
</html>
So, why isn't "bar" anywhere to be found in my output? Shouldn't it appear right after </html>
? Any help would, again, be wonderful :)