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>

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.