次のように、混合コンテンツノード(本文テキストと子ノードの両方を持つ)を使用して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ライブラリの使用例を探してみましたが、ユースケースが見つかりませんでした。どんな助けでも大歓迎です。