Re: [xml-dev] An XML API using Java streams

From
Hans-Juergen Rennau <>
To
Michael Kay <>, "" <>
Date
2017-06-22T13:54:26Z
ID
<>
Thread
Re: [xml-dev] An XML API using Java streams
That does look promising and stirs curiosity. But while you are at it, could you not - at least, in principle - do it exactly the other way around - rather than define representations of flatMap() as /, etc., define a translation of / into flatMap(), etc - in short, a compilation of XPath into your low-level, streaming API expressions? Per mainstream, Java people are using a JAXB compilation step in their build processes anyway, adding an XPath compilation step would not hurt at all, and safety is at its maximum, as is expressiveness.  


Michael Kay <[email protected]> schrieb am 15:33 Donnerstag, 22.Juni 2017:



(2) A great challenge - and perhaps a hopeless one - would be to create an expressiveness which could at least be a far cry of what XPath offers. It is strange to say
     N.walk(Axis.child("city")).flatMap(Axis.attribute("name").map(Node::stringValue)
when what you really want to say is
     city/@name


Excellent point. However, dropping into another language does have all sorts of disadvantages: apart from the learning issues, there's the lack of compile-time syntax checking and type checking, the cost of dynamic compilation/interpretation, etc.

One thing to look at, perhaps, is how it translates into Scala, where you can define your own operators:

A.flatMap(B)   -->   A/B

A.attribute(B)  -->   A @ B

etc; and then we start to have something very XPath-like, but with a syntax that's compiled and validated by the host language.

Michael Kay
Saxonica