Scala XML Pattern matching and Attributes Scala XML Pattern matching and Attributes xml xml

Scala XML Pattern matching and Attributes


Handling attributes is way more of a pain that it should be. This particular example shows, in fact, that Scala doesn't deconstruct XMLs the same way it constructs them, as thissyntax is valid for XML literals. Anyway, here's a way:

myXML match {   case <a>{b @ <b>{theText}</b>}</a> =>     println("An %s text: %s".format(b \ "@type", theText))}