summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2008-04-13 23:48:34 +0000
committerBurak Emir <emir@epfl.ch>2008-04-13 23:48:34 +0000
commitf4ab1e5dfa6e907500c68bdca0decbd33d4369e8 (patch)
tree144e44dd96ac99e6883e74a7296ecb0f8cfa4cb7 /src/library
parent88a96b4ff37f122ae702cc8063731330eba676b5 (diff)
downloadscala-f4ab1e5dfa6e907500c68bdca0decbd33d4369e8.tar.gz
scala-f4ab1e5dfa6e907500c68bdca0decbd33d4369e8.tar.bz2
scala-f4ab1e5dfa6e907500c68bdca0decbd33d4369e8.zip
method NodeSeq#\ supports arguments like "@{uri...
method NodeSeq#\ supports arguments like "@{uri}attrname" for searching prefixed attributes.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/xml/NodeSeq.scala44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala
index f5262a8ea3..e8198eea9c 100644
--- a/src/library/scala/xml/NodeSeq.scala
+++ b/src/library/scala/xml/NodeSeq.scala
@@ -50,7 +50,14 @@ abstract class NodeSeq extends Seq[Node] {
/** Projection function. Similar to XPath, use <code>this \ "foo"</code>
* to get a list of all elements of this sequence that are labelled with
- * <code>"foo"</code>. Use <code>\ "_"</code> as a wildcard.
+ * <code>"foo"</code>. Use <code>\ "_"</code> as a wildcard. Use
+ * <code>ns \ "@foo"</code> to get the unprefixed attribute "foo".
+ * Use <code>ns \ "@{uri}foo"</code> to get the prefixed attribute
+ * "pre:foo" whose prefix "pre" is resolved to the namespace "uri".
+ * For attribute projections, the resulting NodeSeq attribute values are
+ * wrapped in a Group.
+ * There is no support for searching a prefixed attribute by
+ * its literal prefix.
* The document order is preserved.
*
* @param that ...
@@ -72,11 +79,27 @@ abstract class NodeSeq extends Seq[Node] {
NodeSeq.fromSeq(zs.reverse)
case _ if (that.charAt(0) == '@') && (this.length == 1) =>
- val k = that.substring(1)
- val y = this(0)
- y.attribute(k) match {
- case Some(x) => Group(x)
- case _ => NodeSeq.Empty
+ if (that.length() == 1)
+ throw new IllegalArgumentException(that)
+ if (that.charAt(1) == '{') {
+ val i = that.indexOf('}')
+ if (i == -1)
+ throw new IllegalArgumentException(that)
+ val (uri, key) = (that.substring(2,i), that.substring(i+1, that.length()))
+ if (uri == "" || key == "")
+ throw new IllegalArgumentException(that)
+ val y = this(0)
+ y.attribute(uri, key) match {
+ case Some(x) => Group(x)
+ case _ => NodeSeq.Empty
+ }
+ } else {
+ val k = that.substring(1)
+ val y = this(0)
+ y.attribute(k) match {
+ case Some(x) => Group(x)
+ case _ => NodeSeq.Empty
+ }
}
case _ =>
@@ -96,7 +119,14 @@ abstract class NodeSeq extends Seq[Node] {
/** projection function. Similar to XPath, use <code>this \\ 'foo</code>
* to get a list of all elements of this sequence that are labelled with
- * <code>"foo"</code>. Use <code>\\ "_"</code> as a wildcard.
+ * <code>"foo"</code>. Use <code>\\ "_"</code> as a wildcard. Use
+ * <code>ns \\ "@foo"</code> to get the unprefixed attribute "foo".
+ * Use <code>ns \\ "@{uri}foo"</code> to get each prefixed attribute
+ * "pre:foo" whose prefix "pre" is resolved to the namespace "uri".
+ * For attribute projections, the resulting NodeSeq attribute values are
+ * wrapped in a Group.
+ * There is no support for searching a prefixed attribute by
+ * its literal prefix.
* The document order is preserved.
*
* @param that ...