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

Joerg Schmuecker <[email protected]> Wed, 27 Jul 2016 14:13:26 -0700 (PDT)
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
------=_Part_571_1904741886.1469654006252
Content-Type: multipart/alternative; 
	boundary="----=_Part_572_728372985.1469654006253"

------=_Part_572_728372985.1469654006253
Content-Type: text/plain; charset=UTF-8

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.

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

------=_Part_572_728372985.1469654006253
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I looked at some examples on how to transform XML on a nod=
e by node level and ended up looking at=C2=A0https://gist.github.com/zentro=
pe/728034.<div><br></div><div>I find this a very boiler plate heavy and rat=
her object oriented way of doing this. I would prefer to have something mor=
e functional. For example, I can imagine that there is a function defined o=
n scala.xml.Node called tmap that takes a f : ( Node ) =3D&gt; Seq[Node] an=
d applies across the whole tree under the original node.</div><div><br></di=
v><div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, =
250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">val n </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">&lt;a&gt;&lt;b&gt;</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Text</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">/b&gt;&lt;/</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br></span><font color=3D"#000088"><span style=3D"color: #000;" class=3D"=
styled-by-prettify">n</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">tmap</span></font><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"font-family: Monaco; font-size: 11px; color: rgb(147, 26, 104);"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">case</span></spa=
n><span style=3D"font-family: Monaco; font-size: 11px;"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span></span><span style=3D"font-f=
amily: Monaco; font-size: 11px; color: rgb(60, 163, 170);"><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Elem</span></span><span style=3D"=
font-family: Monaco; font-size: 11px;"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span></span><span style=3D"font-family: Monaco; =
font-size: 11px; color: rgb(57, 51, 255);"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">ns</span></span><span style=3D"font-family: Monac=
o; font-size: 11px;"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an></span><span style=3D"font-family: Monaco; font-size: 11px; color: rgb(5=
7, 51, 255);"><span style=3D"color: #080;" class=3D"styled-by-prettify">&qu=
ot;a&quot;</span></span><span style=3D"font-family: Monaco; font-size: 11px=
;"><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span st=
yle=3D"font-family: Monaco; font-size: 11px; color: rgb(114, 122, 255);"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">attribs</span></spa=
n><span style=3D"font-family: Monaco; font-size: 11px;"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span></span><span style=3D"font-family: Mo=
naco; font-size: 11px; color: rgb(114, 122, 255);"><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">scope</span></span><span style=3D"font-fa=
mily: Monaco; font-size: 11px;"><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span></span><span style=3D"font-family: Monaco; font-size: 11px; c=
olor: rgb(114, 122, 255);"><span style=3D"color: #000;" class=3D"styled-by-=
prettify">kids</span></span><span style=3D"font-family: Monaco; font-size: =
11px;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">@</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> _</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> =C2=A0</span></span><font color=3D"#666600"><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font></div></=
code><table class=3D"highlight tab-size js-file-line-container" data-tab-si=
ze=3D"8" style=3D"box-sizing: border-box; border-collapse: collapse; tab-si=
ze: 8; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFo=
nt, &#39;Segoe UI&#39;, Roboto, Helvetica, Arial, sans-serif, &#39;Apple Co=
lor Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-s=
ize: 14px;"><tbody style=3D"box-sizing: border-box;"><tr style=3D"box-sizin=
g: border-box;"><td id=3D"file-transform-scala-LC53" class=3D"blob-code blo=
b-code-inner js-file-line" style=3D"box-sizing: border-box; padding-right: =
10px; padding-left: 10px; position: relative; line-height: 20px; vertical-a=
lign: top; overflow: visible; font-family: Consolas, &#39;Liberation Mono&#=
39;, Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-s=
pace: pre;">                                      &lt;<span class=3D"pl-ent=
" style=3D"box-sizing: border-box; color: rgb(99, 163, 92);">features</span=
>&gt;</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"file-transfo=
rm-scala-L54" class=3D"blob-num js-line-number" data-line-number=3D"54" sty=
le=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px; widt=
h: 50px; min-width: 50px; font-family: Consolas, &#39;Liberation Mono&#39;,=
 Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba=
(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align=
: top; cursor: pointer; -webkit-user-select: none; border-style: solid; bor=
der-color: rgb(238, 238, 238); border-right-width: 1px;"></td><td id=3D"fil=
e-transform-scala-LC54" class=3D"blob-code blob-code-inner js-file-line" st=
yle=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px; pos=
ition: relative; line-height: 20px; vertical-align: top; overflow: visible;=
 font-family: Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospac=
e; font-size: 12px; word-wrap: normal; white-space: pre;">{ features map { =
d <span class=3D"pl-k" style=3D"box-sizing: border-box; color: rgb(167, 29,=
 93);">=3D&gt;</span> &lt;<span class=3D"pl-ent" style=3D"box-sizing: borde=
r-box; color: rgb(99, 163, 92);">feature</span> <span class=3D"pl-e" style=
=3D"box-sizing: border-box; color: rgb(121, 93, 163);">id</span>=3D{d}/&gt;=
 } }</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"file-transfor=
m-scala-L55" class=3D"blob-num js-line-number" data-line-number=3D"55" styl=
e=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px; width=
: 50px; min-width: 50px; font-family: Consolas, &#39;Liberation Mono&#39;, =
Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(=
0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align:=
 top; cursor: pointer; -webkit-user-select: none; border-style: solid; bord=
er-color: rgb(238, 238, 238); border-right-width: 1px;"></td><td id=3D"file=
-transform-scala-LC55" class=3D"blob-code blob-code-inner js-file-line" sty=
le=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px; posi=
tion: relative; line-height: 20px; vertical-align: top; overflow: visible; =
font-family: Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace=
; font-size: 12px; word-wrap: normal; white-space: pre;">&lt;/<span class=
=3D"pl-ent" style=3D"box-sizing: border-box; color: rgb(99, 163, 92);">feat=
ures&gt;<br></span><br>case other =3D&gt; other<br>}</td></tr></tbody></tab=
le></div></div><div><br></div><div>Similar we could implement foldDF for a =
depth first fold and other functors.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">scal=
[email protected]</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />

------=_Part_572_728372985.1469654006253--

------=_Part_571_1904741886.1469654006252--