diff options
author | buraq <buraq@epfl.ch> | 2005-04-11 17:06:19 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2005-04-11 17:06:19 +0000 |
commit | e46aab9c0c8a2f0420a4d1e3d7865b84122f745b (patch) | |
tree | d6e816d4bf32aeb591e315a3a61d8789c1d19081 /test/files/jvm/xmlstuff.scala | |
parent | fa99242159242f676b6b234693060d422762cebd (diff) | |
download | scala-e46aab9c0c8a2f0420a4d1e3d7865b84122f745b.tar.gz scala-e46aab9c0c8a2f0420a4d1e3d7865b84122f745b.tar.bz2 scala-e46aab9c0c8a2f0420a4d1e3d7865b84122f745b.zip |
new XML API that deals with namespaces properly
Diffstat (limited to 'test/files/jvm/xmlstuff.scala')
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 192 |
1 files changed, 13 insertions, 179 deletions
diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index e68f692bdb..1418707f95 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -6,181 +6,8 @@ import scala.xml.{Node,NodeSeq,Elem,Text}; object Test with Application { - val e = Node.NoAttributes; - -/* - def eq( a:Seq[Node], b:Seq[Node] ):boolean = { - (a.length == b.length) && eq(a.elements,b.elements) - } - def eq( ita:Iterator[Node], itb:Iterator[Node] ) = { - var res = true; - while( ita.hasNext && itb.hasNext && res ) { - res = (ita.next == itb.next); - }; - !ita.hasNext && !itb.hasNext && res - } - */ - val xmlFile1 = "<hello><world/></hello>"; - val isrc1 = new InputSource( new StringReader( xmlFile1 ) ); - val parsedxml1 = XML.load( isrc1 ); - val isrc11 = new InputSource( new StringReader( xmlFile1 ) ); - val parsedxml11 = XML.load( isrc11 ); - - val c = new Node { - def label = "hello"; - def namespace = ""; - def child = List(Elem("","world",e)); - def attributes = e; - }; - - assertSameElements( List( 3 ), List( 3 )); - - Console.println("equality"); - assertEquals( c, parsedxml11 ); - assertEquals( parsedxml1, parsedxml11 ); - assertSameElements( List(parsedxml1), List(parsedxml11)); - assertSameElements( Iterator.fromArray(Predef.Array(parsedxml1)).toList, List(parsedxml11)); - - val x2 = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>"; - - val i = new InputSource( new StringReader( x2 )); - val x2p = XML.load( i ); - - assertEquals(x2p, Elem("","book",e, - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web")))); - - val xmlFile2 = "<bib><book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book><book><author>John Mitchell</author><title>Foundations of Programming Languages</title></book></bib>"; - val isrc2 = new InputSource( new StringReader( xmlFile2 ) ); - val parsedxml2 = XML.load( isrc2 ); - - // xmlFile2/book -> book,book - Console.println("xpath \\"); - - - assertSameElements( parsedxml1 \ "_" , List( Elem("","world",e) ) ); - - assertSameElements( parsedxml1 \ "world", List( Elem("","world",e) ) ); - -/* - Console.println( parsedxml2 \ "_" ); - Console.println( (parsedxml2 \ "_" ).elements); - for( val i <- (parsedxml2 \ "_" ).elements) { - Console.println( i ); - }; - */ - assertSameElements( - parsedxml2 \ "_" , - - List( - Elem("","book", e, - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web"))), - Elem("","book",e, - Elem("","author",e,Text("John Mitchell")), - Elem("","title",e,Text("Foundations of Programming Languages")))) - ); - assertEquals( (parsedxml2 \ "author").length, 0 ); - - assertSameElements( - parsedxml2 \ "book", - - List( - Elem("","book",e, - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web"))), - Elem("","book",e, - Elem("","author",e,Text("John Mitchell")), - Elem("","title",e,Text("Foundations of Programming Languages"))) - ) - ); - - assertSameElements( - - parsedxml2 \ "_" \ "_", - - List( - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web")), - Elem("","author",e,Text("John Mitchell")), - Elem("","title",e,Text("Foundations of Programming Languages")) - ) - ); - - assertSameElements( - - parsedxml2 \ "_" \ "author", - - List( - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","author",e,Text("John Mitchell")) - ) - - ); - - assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() ); - - Console.println("xpath \\\\ DESCENDANTS"); - - assertSameElements( - - parsedxml2 \\ "author", - - List( - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","author",e,Text("John Mitchell")) - ) - - ); - - assertEquals( - - (new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_", - - List( - Elem("","bib",e, - Elem("","book",e, - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web"))), - Elem("","book",e, - Elem("","author",e,Text("John Mitchell")), - Elem("","title",e,Text("Foundations of Programming Languages")))), - Elem("","book",e, - Elem("","author",e,Text("Peter Buneman")), - Elem("","author",e,Text("Dan Suciu")), - Elem("","title",e,Text("Data on ze web"))), - Elem("","author",e,Text("Peter Buneman")), - Text("Peter Buneman"), - Elem("","author",e,Text("Dan Suciu")), - Text("Dan Suciu"), - Elem("","title",e,Text("Data on ze web")), - Text("Data on ze web"), - Elem("","book",e, - Elem("","author",e,Text("John Mitchell")), - Elem("","title",e,Text("Foundations of Programming Languages"))), - Elem("","author",e,Text("John Mitchell")), - Text("John Mitchell"), - Elem("","title",e,Text("Foundations of Programming Languages")), - Text("Foundations of Programming Languages") - ) - ); - - - assertSameElements( - - parsedxml2 \\ "title", - - List( - Elem("","title",e,Text("Data on ze web")), - Elem("","title",e,Text("Foundations of Programming Languages"))) - ); + //val e: scala.xml.MetaData = null; //Node.NoAttributes; + //val sc: scala.xml.NamespaceBinding = null; Console.println("NodeSeq"); @@ -221,7 +48,7 @@ object Test with Application { </entry> </reviews>; - Console.println( new scala.xml.PrettyPrinter(80, 5).format ( + Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for( val t <- books \\ "title"; val r <- reviews \\ "entry"; r \ "title" == t) yield @@ -236,7 +63,6 @@ object Test with Application { for( val t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.asList) yield t ); - val phoneBook = <phonebook> <descr> @@ -264,7 +90,7 @@ val addrBook = </entry> </addrbook>; - Console.println( new scala.xml.PrettyPrinter(80, 5).format ( + Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for( val t <- addrBook \\ "entry"; val r <- phoneBook \\ "entry"; t \ "name" == r \ "name") yield @@ -298,6 +124,7 @@ val addrBook = true); /* namespaces */ + // begin tmp Console.println("namespaces"); val cuckoo = <cuckoo xmlns="http://cuckoo.com"> <foo/> @@ -307,7 +134,11 @@ val addrBook = 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 <cuckoo xmlns="http://cuckoo.com"> @@ -316,11 +147,14 @@ val addrBook = </cuckoo> => true; case _ => false; }); */ + /* + // begin tmp assertEquals( false, cuckoo match { case <cuckoo> <foo/> <bar/> </cuckoo> => true; case _ => false; }); - + // end tmp + */ } |