« Return to Thread: Some strengths and weaknesses in Scala's XML capabilities

Re: Some strengths and weaknesses in Scala's XML capabilities

by Daniel Sobral :: Rate this Message:

Reply to Author | View in Thread

At any rate, I'd like to mention that you can use "filter", "map" and "flatMap" on the results of "\" and "\\", which makes it possible to query the XML if not in an XPath-standard way, in the Scala-standard way:

for(n <- library \\ "book"
     if !((n \ "author") filter (_.attribute("id") == "234")).isEmpty
    ) ...

On Mon, Jun 29, 2009 at 12:20 AM, Ben Hutchison <ben@...> wrote:
On Mon, Jun 29, 2009 at 12:15 PM, Marcus Downing<marcus@...> wrote:
>
> Like XML itself, XPath is a standard. An implementation that lets programmers
> from other languages use their existing knowledge without modification is
> better than one that's idiomatically Scalaish. Something like this:
>
>  for (n <- library \ "//book[author/@id=234]") ...

I agree that supporting the standard is good, reuse of knowledge etc.

But, having done some more reading, I suspect Scala has made a
conscious, defensible choice to offer a different API.

AFAIK, the Scala XML rep is a singly-linked list. So, no parent refs
and cannot go backwards through tree. I see now that this means
supporting full XPath was probably not practical without converting to
a DOM rep.

Should Scala offer a XPath query method on Node, if only parts of the
standard are supported, and/or sometimes incur severe performance
costs?

Maybe it should, but make the options clear: High performance default
impl with only "XPath-like" \ & \\ operators, OR, full XPath query
which will force use of more memory hungry & less functional data rep?

-Ben

PS thanks Naftoli, Alex for pointers to <xml:group>



--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.

 « Return to Thread: Some strengths and weaknesses in Scala's XML capabilities