I want to be able to do this:
val myXml = <myTag { someAttributes }> </myTag>
(because I don’t know what the attribute details are at compile time)
and this:
val myXml = <{someTag}></{someTag}>
This isn’t valid Scala syntax. The closest I can come is using the Elem object to construct elements, but it’s being a little troublesome (inserting PCDATA where I don’t want it to). Is there any way of doing it like the above?
See
scala.xml.Attributefor different constructors.Adding the same attribute to all children:
You can also use the stuff in scala.xml.transform to do so recursively to all XML:
Or you can add attributes to arbitrary parts of the xml:
EDIT
Changing the name is easy to do on Scala 2.8, like this: