scala.xml.Utility.trim
.
def createXmlOutput(condition:Boolean) : Elem =
{
val parent: Elem = <something>
<otherchild>{ "my other child value" }</otherchild>
</something>
val child = <child>{ "my child value if condition would be true" }</child>
if(condition == true) parent.copy(child = parent.child :+ child)
else parent
}
你也可以用这样的东西
scala.xml.Utility.trim(createXmlOutput(true))