Skip to content

Commit a38f055

Browse files
buraqadriaanm
buraq
authored andcommitted
modified xml parsing
1 parent 7fe7116 commit a38f055

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

sources/scala/xml/Attribute.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,3 @@ case class Attribute(namespace:String, key:String, value:String) with Ordered[At
2929
}
3030

3131
}
32-
33-
class IntAttribute(namespace:String, key:String, theIntValue:Int)
34-
extends Attribute(namespace, key, theIntValue.toString()) {
35-
final override def intValue = theIntValue;
36-
}

sources/scala/xml/AttributeSeq.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package scala.xml ;
1111

1212
import scala.collection.Map ;
13+
import scala.collection.mutable ;
1314
import scala.collection.immutable.TreeSet ;
1415

1516
object AttributeSeq {
@@ -85,5 +86,16 @@ abstract class AttributeSeq with Seq[Attribute] {
8586
}
8687

8788
override def hashCode():Int = sortedSeq.hashCode();
89+
90+
def toMap:Map[Pair[String,String],Attribute] =
91+
new Map[Pair[String,String],Attribute] {
92+
def elements = new Iterator[Pair[Pair[String,String],Attribute]] {
93+
val it = AttributeSeq.this.sortedSeq.elements;
94+
def hasNext = it.hasNext;
95+
def next = { val a = it.next; Pair(Pair(a.namespace,a.key),a) }
96+
}
97+
def size = AttributeSeq.this.length;
98+
def get(p:Pair[String,String]) = AttributeSeq.this.lookup(p._1, p._2);
99+
}
88100
}
89101

sources/scala/xml/NodeTraverser.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* __ *\
2+
** ________ ___ / / ___ Scala API **
3+
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
4+
** __\ \/ /__/ __ |/ /__/ __ | **
5+
** /____/\___/_/ |_/____/_/ | | **
6+
** |/ **
7+
** $Id$
8+
\* */
9+
10+
package scala.xml ;
11+
12+
import scala.collection.mutable ;
13+
14+
abstract class NodeTraverser[A](handle: parsing.MarkupHandler[A]) {
15+
16+
def traverse(n: Node): Iterable[A] = {
17+
val nb = new mutable.ArrayBuffer[A]();
18+
val it = n.child.elements;
19+
while(it.hasNext) {
20+
nb.appendAll(traverse(it.next));
21+
}
22+
handle.element(0, n.namespace, n.label, n.attributes.toMap, nb)
23+
}
24+
25+
}

sources/scala/xml/parsing/ConstructingHandler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.xml.parsing;
22

3-
import scala.collection.immutable.Map ;
3+
import scala.collection.Map ;
44
import scala.collection.mutable ;
55

66
/** */
@@ -10,7 +10,7 @@ class ConstructingHandler extends MarkupHandler[Node] {
1010

1111
//def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri);
1212

13-
def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[Node]) = {
13+
def element(pos: int, uri: String, label: String, attrMap1: Map[Pair[String,String],Attribute], args: mutable.Buffer[Node]) = {
1414

1515
var attrs = new Array[Attribute](attrMap1.size);
1616
{

sources/scala/xml/parsing/MarkupHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract class MarkupHandler[A] {
4747
* @param attrMap1 the attribute map, from Pair(uri,label) to target
4848
* @param args the children of this element
4949
*/
50-
def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[A]): Iterable[A];
50+
def element(pos: int, uri: String, label: String, attrMap1: Map[Pair[String,String],Attribute], args: mutable.Buffer[A]): Iterable[A];
5151

5252
def charData(pos: Int, txt: String ): Iterable[A];
5353
def procInstr(pos: Int, target: String, txt: String): Iterable[A];

0 commit comments

Comments
 (0)