You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import scala.xml.{Elem, Node, Text}
import scala.xml.transform.{RewriteRule, RuleTransformer}
object XmlTransform extends App {
val name = "contents"
val value = "2"
val InputXml : Node =
<root>
<subnode>1</subnode>
<contents>1</contents>
</root>
val transformer = new RuleTransformer(new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case elem @ Elem(prefix, label, attribs, scope, _) if elem.label == name =>
Elem(prefix, label, attribs, scope, false, Text(value))
case other => other
}
})
println(transformer(InputXml))
}
If I change "case if" statement like
case elem @ Elem(prefix, label, attribs, scope, _) if elem.label == "contents" =>
Elem(prefix, label, attribs, scope, false, Text(value))
It transforms xml as expected. Is it known issue?
The text was updated successfully, but these errors were encountered:
No, probably not. You have come accross an unfortunate name-collision because of the lexical scoping rules of Scala. It's a sconsequence of this class member:
Below program doesn't give expected output
If I change "case if" statement like
It transforms xml as expected. Is it known issue?
The text was updated successfully, but these errors were encountered: