summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/scala/Similarity.scala3
-rw-r--r--sources/scala/xml/NodeSeq.scala39
2 files changed, 35 insertions, 7 deletions
diff --git a/sources/scala/Similarity.scala b/sources/scala/Similarity.scala
index cb41be7f72..68a865ed96 100644
--- a/sources/scala/Similarity.scala
+++ b/sources/scala/Similarity.scala
@@ -10,7 +10,6 @@
package scala;
-// !!! Just a stub to make things compile.
trait Similarity {
- def similar(that: Similarity): boolean = false;
+ def similar(that: Any): boolean;
}
diff --git a/sources/scala/xml/NodeSeq.scala b/sources/scala/xml/NodeSeq.scala
index 83757e9cd5..9865c9bac4 100644
--- a/sources/scala/xml/NodeSeq.scala
+++ b/sources/scala/xml/NodeSeq.scala
@@ -1,14 +1,43 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
+** $Id$
\* */
-// $Id$
+package scala.xml ;
-package scala.xml;
+/* a wrapper that adds some XPath navigation method */
+class NodeSeq( theSeq:Seq[Node] ) extends Seq[Node] {
+ def length = theSeq.length;
+ def elements = theSeq.elements ;
+ def apply( i:int ) = theSeq.apply( i );
-// !!! Just a stub to make things compile.
-class NodeSeq(any: Any);
+ /** projection function. Similar to XPath, use this./'foo to get a list
+ * of all elements of this sequence that are labelled with "foo".
+ * Use /'_ as a wildcard. The document order is preserved.
+ */
+ def \(that: Symbol):NodeSeq = {
+ that.name match {
+ case "_" =>
+ val it = elements.flatMap { x:Node => x.child.elements };
+ new NodeSeq( it.toList );
+ case _ =>
+ val list = elements.flatMap( y =>
+ y.child.elements.filter{ z:Node => z.label == that.name }).toList;
+ new NodeSeq( list );
+ }
+ }
+
+ def \\( that:Symbol ):NodeSeq = {
+ val it = elements.flatMap { x:Node => x.child.elements };
+ val list = (elements.flatMap { x:Node => x.descendant_or_self.elements }).toList;
+ that.name match {
+ case "_" => new NodeSeq( list );
+ case _ => new NodeSeq( list.filter { z:Node => z.label == that.name });
+ }
+ }
+
+}