summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-11-25 14:42:10 +0000
committerburaq <buraq@epfl.ch>2003-11-25 14:42:10 +0000
commit90e43b5df711cfa64bf4d23260fd4a67534e0ae2 (patch)
tree187870e460fa6c649e1e39a35bca55f4ac2d1770 /sources
parent60f05e6378f84e508b44bd664ffbbd11397a5ba0 (diff)
downloadscala-90e43b5df711cfa64bf4d23260fd4a67534e0ae2.tar.gz
scala-90e43b5df711cfa64bf4d23260fd4a67534e0ae2.tar.bz2
scala-90e43b5df711cfa64bf4d23260fd4a67534e0ae2.zip
creation of XML values
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Predef.scala2
-rw-r--r--sources/scala/Symbol.scala19
-rw-r--r--sources/scala/xml/Node.scala25
-rw-r--r--sources/scala/xml/Text.scala3
-rw-r--r--sources/scala/xml/Utility.scala12
-rw-r--r--sources/scala/xml/nobinding/Element.scala9
6 files changed, 33 insertions, 37 deletions
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index e97b60ae87..33c8fa1993 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -55,4 +55,6 @@ object Predef {
def fst[a](x: a, y: Any): a = x;
def scd[a](x: Any, y: a): a = y;
+ val Text = scala.xml.Text;
+
}
diff --git a/sources/scala/Symbol.scala b/sources/scala/Symbol.scala
index 7df7099ae1..6e40861cbc 100644
--- a/sources/scala/Symbol.scala
+++ b/sources/scala/Symbol.scala
@@ -9,6 +9,9 @@
package scala;
+import scala.xml.{Node,Text};
+import scala.xml.nobinding.Element;
+import scala.collection.immutable.ListMap ;
/** Instances of <code>Symbol</code> can be created easily with
* Scala's built-in quote mechanism. For instance, the Scala term
@@ -20,5 +23,21 @@ package scala;
* @version 1.0, 08/08/2003
*/
case class Symbol(name: String) {
+ var map : ListMap[String,String] = ListMap.Empty;
override def toString() = "'" + name;
+ def % (ch:Node*) = new Element(this, List.fromIterator(ch.elements)) {
+ override def attributes = map;
+ };
+ //def > (s:String) = new Element(this, Text(s)::Nil);
+ def % (as:Attribute*) = {
+ for( val a <- as.elements ) {
+ map = map.update(a.name, a.value);
+ }
+ this
+ }
+
+ def -> (value:String) = new Attribute( name, value );
+
+ case class Attribute( name:String, value:String ) ;
+
}
diff --git a/sources/scala/xml/Node.scala b/sources/scala/xml/Node.scala
index 13d29613ce..b7efa44a9a 100644
--- a/sources/scala/xml/Node.scala
+++ b/sources/scala/xml/Node.scala
@@ -1,7 +1,5 @@
package scala.xml ;
-import scala.collection.Map;
-
/** superclass for specific representation of XML elements. These are created by
** a xxx2scala binding tool
**/
@@ -10,27 +8,6 @@ abstract class Node {
def label: String;
def children: Seq[ Node ];
- /** returns a mapping from all present attributes to values */
- def attributes: Map[String,String];
-
- protected val attribHashCode = attributes.toList.hashCode();
-
- /** hashcode for this node*/
- override def hashCode() = Utility.hashCode( label, attribHashCode, children );
-
- def toXML: String = Utility.toXML( this );
-
- def toXML_( elems:Seq[Node] ):String = elems match {
- case head :: tail => head.toXML + toXML_( tail );
- case Nil => "";
- }
-
- override def toString() = {
- var s = new StringBuffer( label );
- s.append("(");
- s.append( children.toString() );
- s.append(")");
- s.toString();
- }
+ def toXML: String;
}
diff --git a/sources/scala/xml/Text.scala b/sources/scala/xml/Text.scala
index a44c5e55e4..1c2b36faf8 100644
--- a/sources/scala/xml/Text.scala
+++ b/sources/scala/xml/Text.scala
@@ -11,9 +11,6 @@ case class Text( text:String ) extends Node {
def label = "#PCDATA";
def children = Nil;
- def attributes = null;
-
- protected override val attribHashCode = 0;
override def toXML = Utility.escape( text );
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala
index 0303e0350a..e0a63b76e6 100644
--- a/sources/scala/xml/Utility.scala
+++ b/sources/scala/xml/Utility.scala
@@ -26,17 +26,17 @@ object Utility {
/** serializes an instance of Node to a string that contains well-formed XML **/
def toXML( n:Node ):String = n match {
case Text( t ) => escape( t );
- case _ =>
+ case x:AttributedNode =>
val s = new StringBuffer();
s.append("<");
- s.append( n.label );
- if( null != n.attributes ) {
- s.append( attr2xml( n.attributes.elements ) );{}
+ s.append( x.label );
+ if( null != x.attributes ) {
+ s.append( attr2xml( x.attributes.elements ) );{}
}
s.append(">");
- s.append( toXML( n.children.elements ) );
+ s.append( toXML( x.children.elements ) );
s.append("</");
- s.append( n.label );
+ s.append( x.label );
s.append(">");
s.toString()
}
diff --git a/sources/scala/xml/nobinding/Element.scala b/sources/scala/xml/nobinding/Element.scala
index 1fb072c79b..8cca908fbe 100644
--- a/sources/scala/xml/nobinding/Element.scala
+++ b/sources/scala/xml/nobinding/Element.scala
@@ -1,16 +1,17 @@
package scala.xml.nobinding;
import scala.collection.Map ;
-import scala.xml.Node ;
+import scala.collection.immutable.ListMap ;
+import scala.xml.{AttributedNode,Node} ;
/** an XML node. use this when data binding is not desired.
**/
-case class Element( symbol: Symbol, ch: List[Node] ) extends Node {
+case class Element( symbol: Symbol, ch: List[Node] ) extends AttributedNode {
def label = symbol.name;
def children = ch;
- def attributes : Map[String,String] = null ; /* overriden at parse time */
-
+ override def attributes : Map[String,String] = ListMap.Empty[String,String] ;
+ override val attribHashCode:int = 0;
}