1

How i can set attribute value like value for elements in scala.xml

This not work :(

def getXml(fooValue: String, barValue: String): Node = 
    val fooBar = <foo bar="{barValue}">
       { fooValue }
    </foo>
crashkin
  • 13
  • 3

2 Answers2

3

You have to do it without quotes: <foo bar={barValue}>

Kolmar
  • 14,086
  • 1
  • 22
  • 25
0

This way it would work:

defintion:

def createXMLElement(value: String, attributeValue: String) : Node =   
<foo attribute={attributeValue}>{value}</foo>

Example

scala> createXMLElement("Hello World", "boring")
res2: scala.xml.Node = <foo attribute="boring">Hello World</foo>

In the example given you assign the result to a val and expect the return type Node. The returntype of the assignement is Unit though.

Andreas Neumann
  • 10,734
  • 1
  • 32
  • 52