diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-14 10:25:09 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-14 10:25:09 -0800 |
commit | 22ed6d493b676e28c324d77a1e31f39672f2a9e1 (patch) | |
tree | 8b368e64d8f07552e64adb5a917a704c2a598caf | |
parent | 89decde4272c1428f884fd4c4d293cb6a8c7af13 (diff) | |
parent | 1426d9cecf1b6123d0dffe44a8ab0dbf88a29707 (diff) | |
download | scala-22ed6d493b676e28c324d77a1e31f39672f2a9e1.tar.gz scala-22ed6d493b676e28c324d77a1e31f39672f2a9e1.tar.bz2 scala-22ed6d493b676e28c324d77a1e31f39672f2a9e1.zip |
Merge pull request #1679 from rtyley/nodeseq-attribute-operator
Add convenience attribute operator to NodeSeq
-rw-r--r-- | src/library/scala/xml/NodeSeq.scala | 5 | ||||
-rw-r--r-- | test/files/jvm/xmlattr.scala | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala index decf60dad7..d2efc947b1 100644 --- a/src/library/scala/xml/NodeSeq.scala +++ b/src/library/scala/xml/NodeSeq.scala @@ -145,6 +145,11 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S } } + /** Convenience method which returns string text of the named attribute. Use: + * - `that \@ "foo"` to get the string text of attribute `"foo"`; + */ + def \@(attributeName: String): String = (this \ ("@" + attributeName)).text + override def toString(): String = theSeq.mkString def text: String = (this map (_.text)).mkString diff --git a/test/files/jvm/xmlattr.scala b/test/files/jvm/xmlattr.scala index d214642eb6..6423268ba7 100644 --- a/test/files/jvm/xmlattr.scala +++ b/test/files/jvm/xmlattr.scala @@ -6,6 +6,7 @@ object Test { UnprefixedAttributeTest() AttributeWithOptionTest() AttributeOutputTest() + AttributeOperatorTest() } object UnprefixedAttributeTest { @@ -60,4 +61,10 @@ object Test { } } + object AttributeOperatorTest { + def apply() { + val xml = <foo bar="apple" /> + assert(xml \@ "bar" == "apple") + } + } } |