|
Scala example source code file (xml02.scala)
The Scala xml02.scala source code
import testing.SUnit._
object Test extends TestConsoleMain {
import scala.xml.{NodeSeq, Utility}
import NodeSeq.seqToNodeSeq
val ax = <hello foo="bar" x:foo="baz" xmlns:x="the namespace from outer space">
<world/>
</hello>
val cx = <z:hello foo="bar" xmlns:z="z" x:foo="baz" xmlns:x="the namespace from outer space">
crazy text world
</z:hello>
val bx = <hello foo="bar&x">
object XmlEx extends TestCase("attributes") with Assert {
override def runTest = {
assertTrue("@one", (ax \ "@foo") xml_== "bar") // uses NodeSeq.view!
assertTrue("@two", (ax \ "@foo") xml_== xml.Text("bar")) // dto.
assertTrue("@three", (bx \ "@foo") xml_== "bar&x") // dto.
assertTrue ("@four", (bx \ "@foo") xml_sameElements List(xml.Text("bar&x")))
assertEquals("@five", "<hello foo=\"bar&x\">", bx.toString)
}
}
object XmlEy extends TestCase("attributes with namespace") with Assert {
override def runTest = {
val z = ax \ "@{the namespace from outer space}foo"
assertTrue("@six", (ax \ "@{the namespace from outer space}foo") xml_== "baz")
assertTrue("@eight", (cx \ "@{the namespace from outer space}foo") xml_== "baz")
try {
ax \ "@"
assertTrue("wrong1", false)
} catch {
case _: IllegalArgumentException =>
}
try {
ax \ "@{"
assertTrue("wrong2", false)
} catch {
case _: IllegalArgumentException =>
}
try {
ax \ "@{}"
assertTrue("wrong3", false)
} catch {
case _: IllegalArgumentException =>
}
}
}
object XmlPat extends TestCase("patterns") with Assert {
override def runTest = {
assertTrue(<hello/> match { case
Other Scala examples (source code examples)Here is a short list of links related to this Scala xml02.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.