val name = "Name";
val value = "Value";
val map = Map(id -> "5", class -> "Nice");
textfield(name, value, map);
def textfield(name: String, value: String, attributes: Map = {}){ //=> Any
val xml = <text name={name} value={value} {attributes.?} />;
}
我正在尝试生产
<text name="Name" value="Value" id="5", class="nice" />
如果可能,我想使用xml文字,但是如果不是我需要使用哪些xml类?
答案 0 :(得分:2)
import scala.xml.{Attribute, Text, Elem}
def textfield(name: String, value: String, attributes: Map[String, String] = Map()) = {
val elem: Elem = <text name={name} value={value} />
(elem /: attributes) {
case (el, att) => el % Attribute(att._1, Text(att._2), xml.Null)
}
}