summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-11-26 09:04:49 +0000
committerburaq <buraq@epfl.ch>2003-11-26 09:04:49 +0000
commit5045628572b5d84e30361f103f5d1aa6e78c584d (patch)
tree6148ffbc625737a3720e5983573be7bdacf9d34e /sources
parent0c15dac9e9985317de7f259da0e3ab90927aa32b (diff)
downloadscala-5045628572b5d84e30361f103f5d1aa6e78c584d.tar.gz
scala-5045628572b5d84e30361f103f5d1aa6e78c584d.tar.bz2
scala-5045628572b5d84e30361f103f5d1aa6e78c584d.zip
new xml nodes
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/xml/AttributedNode.scala30
-rw-r--r--sources/scala/xml/Utility.scala4
2 files changed, 29 insertions, 5 deletions
diff --git a/sources/scala/xml/AttributedNode.scala b/sources/scala/xml/AttributedNode.scala
index 78b97fb0fd..29fb617f87 100644
--- a/sources/scala/xml/AttributedNode.scala
+++ b/sources/scala/xml/AttributedNode.scala
@@ -1,9 +1,33 @@
package scala.xml ;
+import scala.collection.Map;
+
+/** superclass for specific representation of XML elements. These are created by
+** a xxx2scala binding tool
+**/
abstract class AttributedNode extends Node {
-val attribHashCode:int;
-def attributes:scala.collection.Map[String,String];
-def toXML = Utility.toXML(this);
+ final def apply(key:String):Option[String] = attributes.get(key);
+
+ /** returns a mapping from all present attributes to values */
+ def attributes: Map[String,String];
+
+ protected val attribHashCode:int;
+
+ /** hashcode for this node*/
+ override def hashCode() = Utility.hashCode( label, attribHashCode, children );
+
+ final def toXML:String = Utility.toXML( this );
+
+ override def toString() = {
+ var s = new StringBuffer( label );
+ val as = attributes;
+ if( as != null )
+ s.append( Utility.attr2xml( as.elements ) );
+ s.append("(");
+ s.append( children.toString() );
+ s.append(")");
+ s.toString();
+ }
}
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala
index e0a63b76e6..66e0811d46 100644
--- a/sources/scala/xml/Utility.scala
+++ b/sources/scala/xml/Utility.scala
@@ -48,8 +48,8 @@ object Utility {
/** for a Node n, returns string representation of n.attributes **/
def attr2xml( attrib:Iterator[Pair[String, String]] ):String = {
attrib.foldLeft ("") { (s:String,x:Pair[String,String]) => {
- val t = new StringBuffer(" ");
- t.append( s );
+ val t = new StringBuffer(s);
+ t.append( " " );
t.append( x._1 );
t.append("=\"");
t.append( x._2 );