我正在尝试生成具有混合内容节点(具有正文和子节点)的 XML,如下所示:
<person>
some text
<hugo age="24">thingy</hugo>
</person>
我正在使用xmlgen库。
这是我走了多远:
import Text.XML.Generator
import qualified Data.ByteString as B
makeElt = xelem "person" $
xelems $ (xtext "some text" :
(xelem "hugo" (xattr "age" "24" <#>
xtext "thingy")))
main = do
let elt = makeElt
B.putStr . xrender $ doc defaultDocInfo elt
这不会编译,GHC 的错误消息对我来说是无法理解的(作为初学者):
$ runhaskell test.hs
test.hs:6:24:
Couldn't match type `Elem' with `Xml Elem'
The function `xelem' is applied to two arguments,
but its type `[Char]
-> Text.XML.Generator.MkElemRes [Char] (Xml Attr, Xml Elem)'
has only one
In the second argument of `(:)', namely
`(xelem "hugo" (xattr "age" "24" <#> xtext "thingy"))'
In the second argument of `($)', namely
`(xtext "some text"
: (xelem "hugo" (xattr "age" "24" <#> xtext "thingy")))'
test.hs:6:24:
Couldn't match type `Xml' with `[]'
The function `xelem' is applied to two arguments,
but its type `[Char]
-> Text.XML.Generator.MkElemRes [Char] (Xml Attr, Xml Elem)'
has only one
In the second argument of `(:)', namely
`(xelem "hugo" (xattr "age" "24" <#> xtext "thingy"))'
In the second argument of `($)', namely
`(xtext "some text"
: (xelem "hugo" (xattr "age" "24" <#> xtext "thingy")))'
我是否非常接近我需要的结果,或者我应该以不同的方式写这个?
我尝试寻找 xmlgen 库的示例用法,但没有找到我的用例。任何帮助是极大的赞赏。