I am trying to learn to use the xmlgen library, but when I tried the example from http://factisresearch.blogspot.in/2011/05/xmlgen-feature-rich-and-high.html I get a compile error.
Here is the code:
import Text.XML.Generator
import Data.ByteString.Lazy as BSL
import Prelude as P
genXml' :: Xml Doc
genXml' =
let people = [("Stefan", "32"), ("Judith", "4")]
in doc defaultDocInfo $
xelem "people" $
xelems $ P.map (\(name, age) -> xelem "person" (xattr "age" age <#> xtext name)) people
outputXml :: IO ()
outputXml = BSL.putStr (xrender genXml')
The compiler errors:
$ ghc --make prog.hs
[1 of 1] Compiling Main ( prog.hs, prog.o )
prog.hs:13:25:
No instance for (XmlOutput ByteString)
arising from a use of `xrender'
Possible fix:
add an instance declaration for (XmlOutput ByteString)
In the first argument of `BSL.putStr', namely `(xrender genXml')'
In the expression: BSL.putStr (xrender genXml')
In an equation for `outputXml':
outputXml = BSL.putStr (xrender genXml')
The compiler seems to be deducing that "xrender genXML'" needs to be of type "XmlOutput ByteString" and there is an instance of this in the xmlgen library. So please help me with understanding what this error means, and how it can be fixed.
If it helps, I am using the Haskell Platform in Ubuntu 12.10, ghc 7.4.2 and the xmlgen 0.4.0.3