Skip to content

Commit e70ca0a

Browse files
buraqadriaanm
buraq
authored andcommitted
modified xml parsing
1 parent 9926876 commit e70ca0a

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

sources/scala/xml/Attribute.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package scala.xml ;
1919
*/
2020
case class Attribute(namespace:String, key:String, value:String) with Ordered[Attribute] {
2121

22+
def intValue: Int = Integer.parseInt(value);
23+
2224
def compareTo [b >: Attribute <% Ordered[b]](that: b): int = that match {
2325
case z:Attribute =>
2426
val i = key.compareTo( z.key );
@@ -27,3 +29,8 @@ case class Attribute(namespace:String, key:String, value:String) with Ordered[At
2729
}
2830

2931
}
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/parsing/ConstructingHandler.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ import scala.collection.mutable ;
66
/** */
77
class ConstructingHandler extends MarkupHandler[Node] {
88

9-
def attributeCDataValue(pos: int, str:String) = CDataValue(str);
9+
//def attributeCDataValue(pos: int, str:String) = CDataValue(str);
1010

11-
def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri);
11+
//def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri);
1212

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

1515
var attrs = new Array[Attribute](attrMap1.size);
1616
{
1717
var i = 0;
1818
val it = attrMap1.elements;
1919
while( it.hasNext ) {
20-
val Pair(Pair(uri:String, key:String), va: AttribValue) = it.next;
20+
val Pair(Pair(uri:String, key:String), va: Attribute) = it.next;
21+
attrs( i ) = va;
22+
/*
2123
va match {
2224
case CDataValue(str) => attrs( i ) = Attribute(uri, key, str);
2325
}
26+
*/
2427
i = i + 1;
2528
}
2629
}

sources/scala/xml/parsing/MarkupHandler.scala

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,18 @@ abstract class MarkupHandler[A] {
2727
if( i != -1 ) Some( name.substring(0, i) ) else None
2828
}
2929

30-
/** removes xmlns attributes from attr as a side effect, and returns a prefix
31-
* map resulting from them
32-
* /
33-
final def namespaceDecl1(aMap: mutable.Map[String, AttribValue]): Map[String, String] = {
34-
val setNS = new mutable.HashMap[String, String];
35-
/ * DEBUG * /
36-
val attrIt = aMap.keys;
37-
while( attrIt.hasNext ) {
38-
val z = attrIt.next;
39-
if( z.startsWith("xmlns") ) {
40-
val uri = aMap( z ) match {
41-
case NamespaceDecl(uri1) => uri1;
42-
case _ => throw FatalError("bad namespace declaration");
43-
}
44-
val i = z.indexOf(':');
45-
if( i == -1 )
46-
setNS.update("", uri );
47-
else {
48-
val zz = z.substring( i+1, z.length() );
49-
setNS.update( zz, uri );
50-
}
51-
aMap -= z;
52-
}
53-
}
54-
setNS;
55-
}
56-
*/
57-
5830
/** removes xmlns attributes from attr as a side effect, and returns a prefix
5931
* map resulting from them
6032
*/
6133
final def internal_namespaceDecl(prefix:String, uri:String): Unit = {
6234
tmpPrefix.update(prefix, uri);
6335
}
6436

65-
def attributeCDataValue(pos: int, str:String): AttribValue;
66-
def attributeNamespaceDecl(pos: int, uri: String): AttribValue;
37+
//def attributeCDataValue(pos: int, str:String): Attribute;
38+
//def attributeNamespaceDecl(pos: int, uri: String): Attribute;
6739

68-
def attribute(pos: int, uri: String, key: String, value:String): AttribValue =
69-
attributeCDataValue(pos, value);
40+
def attribute(pos: int, uri: String, key: String, value:String) =
41+
Attribute(uri,key,value);
7042

7143
/** be careful to copy everything from attrMap1, as it will change
7244
* @param pos the position in the sourcefile
@@ -75,7 +47,7 @@ abstract class MarkupHandler[A] {
7547
* @param attrMap1 the attribute map, from Pair(uri,label) to target
7648
* @param args the children of this element
7749
*/
78-
def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],AttribValue], args: mutable.Buffer[A]): Iterable[A];
50+
def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[A]): Iterable[A];
7951

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

sources/scala/xml/parsing/MarkupParser.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package scala.xml.parsing;
1111

12+
import scala.xml.Attribute;
1213
import scala.collection.{ mutable, Map };
1314
import scala.collection.immutable.ListMap;
1415

@@ -39,10 +40,10 @@ abstract class MarkupParser[MarkupType] {
3940
/** append Unicode character to name buffer*/
4041
protected def putChar(c: Char) = cbuf.append(c);
4142

42-
protected var aMap: mutable.Map[String,AttribValue] = _;
43+
protected var aMap: mutable.Map[String,Attribute] = _;
4344

4445
final val noChildren = new mutable.ListBuffer[MarkupType];
45-
final val noAttribs = new mutable.HashMap[Pair[String,String], AttribValue];
46+
final val noAttribs = new mutable.HashMap[Pair[String,String], Attribute];
4647

4748
//var xEmbeddedBlock = false;
4849

@@ -132,7 +133,7 @@ abstract class MarkupParser[MarkupType] {
132133
}
133134
// @todo, iterate over attributes, replace prefix, call handleAttribute.
134135
handle.internal_startPrefixMapping;
135-
val aMap1 = new mutable.HashMap[Pair[String,String],AttribValue];
136+
val aMap1 = new mutable.HashMap[Pair[String,String],Attribute];
136137
val it = aMap.elements;
137138
while( it.hasNext ) {
138139
val x @ Pair(Pair(pref,key),Pair(pos,value)) = it.next;
@@ -169,11 +170,11 @@ abstract class MarkupParser[MarkupType] {
169170
* [40] STag ::= '&lt;' Name { S Attribute } [S]
170171
* [44] EmptyElemTag ::= '&lt;' Name { S Attribute } [S]
171172
*/
172-
protected def xTag: Pair[String, mutable.Map[Pair[String,String],AttribValue]] = {
173+
protected def xTag: Pair[String, mutable.Map[Pair[String,String],Attribute]] = {
173174
val elemqName = xName;
174175

175176
xSpaceOpt;
176-
val aMap: mutable.Map[Pair[String,String],AttribValue] =
177+
val aMap: mutable.Map[Pair[String,String],Attribute] =
177178
if(xml.Parsing.isNameStart( ch )) {
178179
xAttributes;
179180
} else {

0 commit comments

Comments
 (0)