object Test { def main(args: Array[String]) { XmlEx.run() XmlEy.run() XmlPat.run() DodgyNamespace.run() } import scala.xml.{NodeSeq, Utility} import NodeSeq.seqToNodeSeq val ax = val cx = crazy text world val bx = object XmlEx { def run() { assert((ax \ "@foo") xml_== "bar") // uses NodeSeq.view! assert((ax \ "@foo") xml_== xml.Text("bar")) // dto. assert((bx \ "@foo") xml_== "bar&x") // dto. assert((bx \ "@foo") xml_sameElements List(xml.Text("bar&x"))) assert("" == bx.toString) } } object XmlEy { def run() { val z = ax \ "@{the namespace from outer space}foo" assert((ax \ "@{the namespace from outer space}foo") xml_== "baz") assert((cx \ "@{the namespace from outer space}foo") xml_== "baz") try { ax \ "@" assert(false) } catch { case _: IllegalArgumentException => } try { ax \ "@{" assert(false) } catch { case _: IllegalArgumentException => } try { ax \ "@{}" assert(false) } catch { case _: IllegalArgumentException => } } } object XmlPat { def run() { assert( match { case => true; case _ => false; }) assert( match { case => true; case _ => false; }); assert(Utility.trim(cx) match { case n @ crazy text world if (n \ "@foo") xml_== "bar" => true; }) assert(Utility.trim(cx) match { case n @ crazy text world if (n \ "@foo") xml_== "bar" => true; }) } } object DodgyNamespace { def run() { val x = assert(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*")); } } }