だから私はスカラーXml要素のリストを単一のスカラ要素に変換する方法は?
val list:List[Any];
def toElement(a:Any):scala.xml.Elem;
を持っていると私は私が正しくあなたを理解している場合
val result = <span> {list.map(toElement).toElem} <span>
だから私はスカラーXml要素のリストを単一のスカラ要素に変換する方法は?
val list:List[Any];
def toElement(a:Any):scala.xml.Elem;
を持っていると私は私が正しくあなたを理解している場合
val result = <span> {list.map(toElement).toElem} <span>
<span> <1></1><2></2><test></test><3.5></3.5> </span>
val list:List[Any] = List(1, 2, "test", 3.5)
def toElement(a:Any):scala.xml.Elem = {
scala.xml.Elem(null, a.toString, scala.xml.Null, scala.xml.TopScope)
}
val result = <span> { list map toElement } </span>
結果
のように気にいらを書きたい、私は何を後にしていることは、このようなものかもしれないと思う:
// List of different types
val list: List[Any] = List("one", 2, "three", 4:Long)
// Conversion function for type 'Any' - (note .toElem or .toXml isn't a
// member of 'Any' - so that's why we need to create this)
def toElement(a: Any): scala.xml.Elem = <hello>{ a.toString }</hello>
// Usage example
val result = <span>{ list.map(toElement(_)) }</span>
しかし、実際にはどのような種類のオブジェクトがリスト内にあるのか、そしてどんな種類のXML要素が好きに見えるのかによって決まると思います。