Suppose I need to get the attribute value in Scala. I can assume that the attribute is a string (and if it is not this is an error).
Since the scala.xml API (MetaData.get(name: String):Option[Seq[Node]]) looks rather complex I wrote a helper function:
def attributeValue(e: Elem, aname: String): Option[String] = for {
seq <- e.attributes.get(aname)
value <- seq.collectFirst {case Text(txt) => txt}
} yield value
Does it make sense ? How would you change/fix this code