summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-03-11 13:49:29 +0000
committerburaq <buraq@epfl.ch>2004-03-11 13:49:29 +0000
commitd95cab4184fb13970440abec5a5b346c8c67944f (patch)
treec1ceb7df3dccd5a12ac710a9a978c9fc806aaed4
parentcce47063a68e12d93e654fd390205ae486160d73 (diff)
downloadscala-d95cab4184fb13970440abec5a5b346c8c67944f.tar.gz
scala-d95cab4184fb13970440abec5a5b346c8c67944f.tar.bz2
scala-d95cab4184fb13970440abec5a5b346c8c67944f.zip
better XPath syntax
-rw-r--r--sources/scala/xml/Node.scala30
-rw-r--r--sources/scala/xml/Text.scala9
2 files changed, 20 insertions, 19 deletions
diff --git a/sources/scala/xml/Node.scala b/sources/scala/xml/Node.scala
index a07279065c..f050b35dc1 100644
--- a/sources/scala/xml/Node.scala
+++ b/sources/scala/xml/Node.scala
@@ -25,13 +25,13 @@ trait Node {
* of all children of this node that are labelled with "foo".
* The document order is preserved.
*/
- def /(that:Symbol): NodeSeq = new NodeSeq({
+ def |(that:Symbol): NodeSeq = new NodeSeq({
val iter = children.elements;
- if( "_" == that.label ) {
+ if( "_" == that.name ) {
List.fromIterator( iter );
} else {
var res:List[Node] = Nil;
- for( val x <- iter; x.label == that.label ) {
+ for( val x <- iter; x.label == that.name ) {
res = x::res;
}
res.reverse
@@ -43,13 +43,13 @@ trait Node {
* Use /'_ as a wildcard.
* The document order is preserved.
*/
- def /#(that:Symbol): NodeSeq = new NodeSeq({
+ def ||(that:Symbol): NodeSeq = new NodeSeq({
var res:List[Node] = Nil;
var tmp:List[Node] = Nil;
for( val x <- children.elements ) {
- if ( x.label == that.label || "_" == that.label )
+ if ( x.label == that.name || "_" == that.name )
tmp = x::tmp;
- tmp = tmp:::(x/#(that)).toList;
+ tmp = tmp:::(x||(that)).toList;
res = res:::tmp;
tmp = Nil
}
@@ -66,26 +66,26 @@ class NodeSeq(theList:List[Node]) extends Seq[Node] {
* of all elements of this sequence that are labelled with "foo".
* Use /'_ as a wildcard. The document order is preserved.
*/
- def /(that: Symbol) = if( "_" == that.label ) {
+ def |(that: Symbol) = if( "_" == that.name ) {
new NodeSeq( res )
} else {
- new NodeSeq( res.filter( y => y.label == that.label ))
+ new NodeSeq( res.filter( y => y.label == that.name ))
}
/** projection function. Similar to XPath, use this./'foo to get a list
* of all children of this node that are labelled with "foo"
- * Use /#'_ as a wildcard. The document order is preserved.
+ * Use ||'_ as a wildcard. The document order is preserved.
*/
- def /#(that: Symbol): NodeSeq = new NodeSeq(
- if ( "_" == that.label ) {
- theList.flatMap ( x => (x/#'_).toList )
+ def ||(that: Symbol): NodeSeq = new NodeSeq(
+ if ( "_" == that.name ) {
+ theList.flatMap ( x => (x||'_).toList )
} else {
theList.flatMap ( x => {
- if( x.label == that.label )
- x::(x/#(that)).toList;
+ if( x.label == that.name )
+ x::(x||(that)).toList;
else
- (x/#(that)).toList;
+ (x||(that)).toList;
})
});
diff --git a/sources/scala/xml/Text.scala b/sources/scala/xml/Text.scala
index bbb2a20e12..bb1ec0354c 100644
--- a/sources/scala/xml/Text.scala
+++ b/sources/scala/xml/Text.scala
@@ -25,14 +25,15 @@ case class Text( text:String ) extends Node {
*/
final def children = Nil;
- /** returns PCDATA text, with some characters escaped according to XML spec
- */
- override def toXML = Utility.escape( text );
override def hashCode() = text.hashCode();
/** returns "Text("+raw text+")"
*/
- override def toString() = "Text("+text+")";
+ override def toString() = Utility.escape( text );
+
+ /** returns PCDATA text, with some characters escaped according to XML spec
+ */
+ override def toXML = Utility.escape( text );
}