Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:41:04+00:00 2026-06-18T01:41:04+00:00

I am trying to generate XML with mixed content nodes (has both body text

  • 0

I am trying to generate XML with mixed content nodes (has both body text and children nodes), like the following:

<person>
some text
<hugo age="24">thingy</hugo>
</person>

I am using the xmlgen library.

Here’s how far I got:

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

This does not compile and GHC’s error message is incomprehensible to me (as a beginner):

$ 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")))'

Am I quite close to the result that I need, or should I be writing this differently?

I tried looking for examples usage of the xmlgen library but didn’t find my use-case. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:41:05+00:00Added an answer on June 18, 2026 at 1:41 am

    The problem is in the expression

    (xtext "some text" : 
     (xelem "hugo" (xattr "age" "24" <#> 
                    xtext "thingy")))
    

    The part after the : (starting with xelem "hugo") is not a list. I good way to debug such type problems is using ghci. That’s what I did in the first place, and the ghci quickly leads you in the right direction:

    *Text.XML.Generator> :t xtext "some text" : xelem "hugo" (xattr "age" "24" <#> xtext "thingy")
    
    <interactive>:1:21:
        Couldn't match expected type `[Xml Elem]'
                    with actual type `Xml Elem'
        In the return type of a call of `xelem'
        In the second argument of `(:)', namely
          `xelem "hugo" (xattr "age" "24" <#> xtext "thingy")'
        In the expression:
          xtext "some text"
          : xelem "hugo" (xattr "age" "24" <#> xtext "thingy")
    

    A good question is why GHC give’s such a bad error message in the first place. The problem is that the result type of xelem is overloaded, in fact xelem has type n -> MkElemRes n c. The instantiation for MkElemRes n c you are trying to use in your example is indeed a function type, so this part of your example is correct. But in general MkElemRes n c does not need to be a function type and that’s why GHC complains about two arguments where it expects only one (namely one of type MkElemRes n c).

    Here are one solution to your original problem:

    xelem "person" $ 
       xelems [xtext "some text", xelem "hugo" (xattr "age" "24" <#> xtext "thingy")]
    

    Here is an alternative solution:

    xelem "person" $ xtext "some text" <> xelem "hugo" (xattr "age" "24" <#> xtext "thingy")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to generate xml in the following format: <Root> <Domain>Abc</Domain> <Name>Xyz</Name> <Contents> <Content>
I am trying to generate an xml file of a recipe database that has
I'm trying to generate some XML using XML::Builder, but my element names need to
I'm trying to generate an XML file with the my machine's hostname in some
I am trying to generate the following XML in my SOAP call: <CResponse> <ID>int</ID>
I'm trying to generate some XML for a jQuery.get (AJAX) call, and I'm getting
I am trying to generate some xml with this php code here... I am
I'm trying to generate an XML schema using JAXBContext.generateSchema(..). My class looks something like
I'm trying to generate an XML file. I've got some tags that repeat numerically
I'm trying to generate an XML document like the one below. I tried several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.