Created
May 27, 2012 20:06
-
-
Save soc/2815694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package example.dynamicxml | |
| import language.dynamics | |
| class DynamicXML(x: scala.xml.NodeSeq, attributeMode: Boolean = false) extends Dynamic { | |
| def selectDynamic(name: String) = { | |
| if (attributeMode) { | |
| println(s"... selecting attribute $name") | |
| new DynamicXML(x \ (s"@$name")) | |
| } else { | |
| println(s"... selecting element $name") | |
| new DynamicXML(x \ name) | |
| } | |
| } | |
| def applyDynamic(name: String)(value: String) = { | |
| assert(!attributeMode) | |
| println(s"... applying $name with value $value") | |
| (x \ name \ (s"@$value")).text | |
| } | |
| def getXml = { | |
| println("... calling getXml") | |
| x | |
| } | |
| def text = { | |
| println("... calling text") | |
| x.text | |
| } | |
| def @@ = { | |
| assert(!attributeMode) | |
| println("... calling @@") | |
| new DynamicXML(x, true) | |
| } | |
| def attribute = { | |
| assert(!attributeMode) | |
| println("... calling attribute") | |
| new DynamicXML(x, true) | |
| } | |
| } | |
| object DynamicXML { | |
| implicit def apply(x: scala.xml.NodeSeq) = new DynamicXML(x) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment