Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created February 28, 2010 12:21
Show Gist options
  • Save kmizu/317557 to your computer and use it in GitHub Desktop.
Save kmizu/317557 to your computer and use it in GitHub Desktop.
import scala.xml._
object Attrs {
def unapplySeq(data: MetaData): Option[Seq[(String, String)]] = {
Some(data.map{(m:MetaData) => (m.key, m.value(0).text)}.toList)
}
def main(args: Array[String]) {
val foo = <foo a="1" b="2" c="3"/>
//困ったことに、XMLリテラルは属性の順番を保存してくれないので、
//ファイルから読み込むとか別の方法が必要
//XML.loadStringとかだと属性が逆順で読み込まれるっぽい
//ので、これも微妙
val Attrs((k1, v1), (k2, v2), (k3, v3)) = foo.attributes
println((k1, v1), (k2, v2), (k3, v3))
val foo2 = XML.loadString("""<foo a="1" b="2" c="3"/>""")
val Attrs(("c", cValue), ("b", bValue), ("a", aValue)) = foo2.attributes
println(("a", aValue), ("b", bValue), ("c", cValue))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment