2012-03-15 2 views

答えて

0

<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> 

結果

1

のように気にいらを書きたい、私は何を後にしていることは、このようなものかもしれないと思う:

// 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要素が好きに見えるのかによって決まると思います。

関連する問題