import java.io.StringReader; import org.xml.sax.InputSource; import scala.testing.UnitTest._ ; import scala.xml.{Node, NodeSeq, Elem, Text, XML}; object Test with Application { //val e: scala.xml.MetaData = null; //Node.NoAttributes; //val sc: scala.xml.NamespaceBinding = null; Console.println("NodeSeq"); import scala.xml.Utility.view ; val p = ; assertSameElements( for( val x <- p \ "bar"; val y <- p \ "baz" ) yield { x.attribute("value") + y.attribute("bazValue")+ "!" }, new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) } ); val books = Blabla Blubabla Baaaaaaalabla ; val reviews = Blabla Hallo Welt. Blubabla Hello Blu Blubabla rem 2 ; Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for( val t <- books \\ "title"; val r <- reviews \\ "entry"; r \ "title" == t) yield { t } { r \ "remarks" } )); // example Console.println( for( val t @ Blabla <- new NodeSeq { val theSeq = books.child }.asList) yield t ); val phoneBook = This is the phonebook of the ACME corporation. John +41 21 693 68 67 +41 79 602 23 23 ; val addrBook = This is the addressbook of the ACME corporation. John Elm Street Dolphin City ; Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for( val t <- addrBook \\ "entry"; val r <- phoneBook \\ "entry"; t \ "name" == r \ "name") yield { t.child } { r \ "phone" } )); /* patterns */ Console.println("patterns"); assertEquals( match { case => true; case _ => false; }, true); assertEquals( match { case => true; case _ => false; }, true); assertEquals( crazy text world match { case crazy text world => true; case _ => false; }, true); /* namespaces */ // begin tmp Console.println("namespaces"); val cuckoo = ; assertEquals( cuckoo.namespace, "http://cuckoo.com"); for( val n <- cuckoo.child ) { assertEquals( n.namespace, "http://cuckoo.com"); } // end tmp /* DEPRECATED, don't support namespaces in pattern match anymore */ /* assertEquals( true, cuckoo match { case => true; case _ => false; }); */ /* // begin tmp assertEquals( false, cuckoo match { case => true; case _ => false; }); // end tmp */ }