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

  • SEARCH
  • Home
  • 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 7578955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:33:21+00:00 2026-05-30T17:33:21+00:00

Admittedly I really love the Jerkson library because it makes generating JSON so easy.

  • 0

Admittedly I really love the Jerkson library because it makes generating JSON so easy. Take for example:

Json(generate(Job.search(parseDate(date),accountId)
      .map(job => Map("id" -> job.id,
      "name" -> job.name,
      "userId" -> job.userId.getOrElse("")
    ))))

But I am having difficulty finding a similar library that could generate and serialize XML nodes, etc., as easily as this. Is there a Java or Scala lib that could generate the nodes and values in a simple syntax without having to make “templates” or manually write the nodes?

  • 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-05-30T17:33:22+00:00Added an answer on May 30, 2026 at 5:33 pm

    It’s much more difficult to build XML than JSON, because of the “double hierarchy” of attributes and children nodes. JSON structure is easily represented with standard Scala collections, by nesting maps and lists.

    But if your are just interested in a subset of XML, the problems is less complex. According to your answer to my comment, the following snippet could be enough for what you need:

    def tag( name: String, content: Seq[Node] ): Node =
      <xml></xml>.copy( label = name, child = content )
    
    def toXML( label: String, content: String ): Node =
      tag( label, Text( content ) ) 
    
    def toXML( root: String, map: Map[_,_] ): Node = {
      val children = for( (k,v) <- map ) yield {
        v match {
          case m: Map[_,_] => toXML( k.toString, m )
          case a => toXML(k.toString, a.toString )
        }
      }
      tag( root, children.toSeq )
    }
    

    It works as expected. For instance:

     val data = Map(
      "id" -> 121,
      "foo" -> Map(
        "hoo" -> "bar",
        "goo" -> "baz"
      )
    )
    
    val xml = convert.toXML( "example", data )
    

    Then xml will be equal to:

    <example>
      <id>121</id>
      <foo>
        <hoo>bar</hoo>
        <goo>baz</goo>
      </foo>
    </example>
    

    It’s just a quick and dirty hack, but I think it can be easily improved (to include lists for instance) and made safer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look, for example at AppleScript (and there are plenty of others, some admittedly quite
There are a couple of things I find really annoying about Visual Studio. Admittedly,
I'm looking at options for providing Faceted Search functionality, admittedly not a specialty of
Admittedly, creating extmap.xml files is relatively simple: http://msdn.microsoft.com/en-us/library/dd833069(VS.95).aspx But while many third-party libraries provide
Admittedly not a programming question, but I don't really know where else to ask
Admittedly I don't get it. Say you have a memory with a memory word
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
In my admittedly young career I've found myself writing code to support quirky business
This is admittedly a rather loose question. My current understanding of singletons is that
Compared to most people on this site I am admittedly a novice. I wanted

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.