XML : Scala: How do I programmatically create an XML tag and insert a value in it?

I currently have something like this:

  val green = "GREEN"    

I want to programmatically create a tag and insert green as its only child. it should look like this:

  val blue = if(blah) "INDIGO" else "SKY"  val fooElem:Elem = <{blue}> green<{blue}>    

obviously, this does not work. I then find out that an empty Elem can be generated like this:

  val fooEmpty = new Elem(null, blue, scala.xml.Null , scala.xml.TopScope, false) //this is <INDIGO></INDIGO> or <SKY></SKY>    

Now, I do not know how to programmatically add green as its child/value so that it becomes fooElem. How can I do this?

No comments:

Post a Comment