1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.xml;
/** The case class <code>Elem</code> extends the Node class,
* providing an immutable data object representing an XML element.
*
* @param prefix (may be null)
* @param label the element name
* @param attribute the attribute map
* @param child the children of this node
* @author Burak Emir
*/
// "val" is redundant for non-overriding arguments
case class Elem(override val prefix: String,
val label: String,
override val attributes: MetaData,
override val scope: NamespaceBinding,
val child: Node*) extends Node {
if (prefix != null && 0 == prefix.length())
throw new IllegalArgumentException("prefix of zero length, use null instead");
if (null == scope)
throw new IllegalArgumentException("scope is null, try xml.TopScope for empty scope");
//@todo: copy the children,
// setting namespace scope if necessary
// cleaning adjacent text nodes if necessary
final override def typeTag$: Int = 0;
override def hashCode(): Int = {
Utility.hashCode(prefix, label, attributes.hashCode(), scope.hashCode(), child);
}
/** Return a new element with updated attributes
*
* @param attrs
* @return a new symbol with updated attributes
*/
final def %(attrs: MetaData): Elem =
Elem(prefix,
label,
attrs.append(attributes),
scope,
child:_*);
/* returns concatenation of text(n) for each child n */
override def text = {
val sb = new compat.StringBuilder();
val it = child.elements;
while(it.hasNext) {
sb.append(it.next.text);
}
sb.toString()
}
}
|