Is there are more functional way to transform XML than using RewriteRule and RuleTransformer?

45 views
Skip to first unread message

Joerg Schmuecker

unread,
Jul 27, 2016, 5:13:26 PM7/27/16
to scala-language
I looked at some examples on how to transform XML on a node by node level and ended up looking at https://gist.github.com/zentrope/728034.

I find this a very boiler plate heavy and rather object oriented way of doing this. I would prefer to have something more functional. For example, I can imagine that there is a function defined on scala.xml.Node called tmap that takes a f : ( Node ) => Seq[Node] and applies across the whole tree under the original node.

val n = <a><b>Text</b></a>

n.tmap
{ case Elem(ns, "a", attribs, scope, kids @ _*) =>  
<features>
{ features map { d => <feature id={d}/> } }
</features>

case other => other
}

Similar we could implement foldDF for a depth first fold and other functors.
Reply all
Reply to author
Forward
0 new messages