Re: [groovy-user] Some groovy community help please

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
29 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Alan-19
* Alan <[hidden email]> [2005-10-28 18:57]:

> * John Wilson <[hidden email]> [2005-10-28 12:38]:
> >
> > On 28 Oct 2005, at 17:21, Babelex wrote:
> >
> > >I agree Jonh on the long term path i.e. getting gpath to do all that
> > >xpath can but in a groovy way. The only reason i suggest the
> > >node.xpath('//table") is a way to get around current gpath/slurper
> > >limitations. In the long run the xpath can be depreciated. It's also
> > >usefull for those coming from other languages including java who
> > >already know xpath (very common). For instance I teach many xml
> > >programmers how to use scripting, they already have xml up their
> > >sleeve this could make it even eisier for them.
> >
> > I understand the motivation:) However there are real technical  
> > difficulties.
> >
> > Slurper builds a very basic tree because it wants to be able to  
> > process very large documents in minimum memory. We certainly could  
> > generate a w3C DOM from this data (because we have a  
> > StreamingDOMBuilder which understands XMLSlurper GPath objects).  
> > However round tripping the data GPath tree -> DOM apply XPath  
> > expression -> GPath tree would be memory hungry and slow. So whilst  
> > it's doable I don't think its that useful.

>     W3C DOM. Gak!

>     Jaxen traverses it's document using an interator interface. You
>     can implement a Navigator for whatever object model, as long at
>     that model models an XML Infoset. (I sure someone has already
>     created one for navigating Java Beans as XML.)

>     Saxon to has a node interface that can be wrapped around any
>     DOM that models an XML Infoset.

>     Both use axis for navigation, rather than pointer navigation.

> > If you feel like giving it a try please  do - you can add an xpath  
> > function to the groovy.util.slurpersupport.GPathResult type via the  
> > "use" mechanism. I would be interested in seeing how such a scheme  
> > works - I may well be wrong about its utility.

    Giving it a try...

    JAXP is out, since it would require turning the document into
    something beside GPathResult nodes. Saxon's NodeInfo interface
    is going to expect meaningful namespaces in scope, and it is
    going to want a quick document order comparison. This is the one
    thing that might make it difficult. Also, it looks as though the
    parent node is not implemented.

    Since Node has a linked list of children, the iterators for an
    XPath implementation can be implemented using ListIterators.

    Cheers.

--
Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
Reply | Threaded
Open this post in threaded view
|

RE: [groovy-user] Some groovy community help please

Dierk König
cool!

The user only has to put dom4j.jar on the cp.

BTW: I started throwing all such jars in my ~/.groovy/lib.
That's very convenient but may become a class-loading
performance and versioning problem over time.
Are there any ideas about supporting something like
Ruby-Gems?

cheers
Mittie

> -----Original Message-----
> From: Babelex [mailto:[hidden email]]
> Sent: Samstag, 29. Oktober 2005 1:52
> To: [hidden email]
> Subject: Re: [groovy-user] Some groovy community help please
>
>
> Yup not having JAXP 1.3 in jsdk 1.4 is a bind.
>
> I do a lot of work on my Powerbook and all you get is jsdk1.4!!
>
> you can get a jsdk 1.5 version if you install tiger (there is a
> download on  the apple dev site, but it's not finished yet)
>
> Also I don't have tiger on my laptop yet so that sucks anyhow.
>
> I did follow suns instalation of the JAXP 1.3 on a Jsdk 1.4 insalation
> using the endorse folder, but after doing so eclipse 3.1 would boot no
> longer and I couldn't fathom the exact cause...
>
> I have just been playoing with dom4j as recomended by Mittie
> , Good fun and it doesn't neeed JAXP 1.4 for the Xpath stuff.
>
> Just burned a solution to the start of this thread :
>
> import org.dom4j.Document
> import org.dom4j.DocumentException
> import org.dom4j.io.SAXReader
>
> class G4j {
>
>     static void main(args) {
> println "Testing table parse of " + args[0]
>    def g4 = new G4j()
>    def tables = g4.xpath(new
> URL(args[0]),"//table[not(descendant::table)]")
>    tables.each(){
>     println it.valueOf("@title")
>    }
> }
>
> def parse(url) {
>         def reader = new SAXReader()
>         return reader.read(url)
>     }
>
>     def xpath(url,path){
>     def doc = parse(url)
>     return doc.selectNodes(path)
>     }
> }
>
> This works nicely, but is not very groovy. I need to get the recursion
> and other stuff fixed in groovy first, any help would be appreciated
> here (as per earlier post).
>
> That little above demo just prints the titles (title attributes) of
> the tables that don't have tables in them as required.
>
>
> On 10/28/05, Alan <[hidden email]> wrote:
> > * John Wilson <[hidden email]> [2005-10-28 12:38]:
> > >
> > > On 28 Oct 2005, at 17:21, Babelex wrote:
> > >
> > > >I agree Jonh on the long term path i.e. getting gpath to do all that
> > > >xpath can but in a groovy way. The only reason i suggest the
> > > >node.xpath('//table") is a way to get around current gpath/slurper
> > > >limitations. In the long run the xpath can be depreciated. It's also
> > > >usefull for those coming from other languages including java who
> > > >already know xpath (very common). For instance I teach many xml
> > > >programmers how to use scripting, they already have xml up their
> > > >sleeve this could make it even eisier for them.
> > >
> > > I understand the motivation:) However there are real technical
> > > difficulties.
> > >
> > > Slurper builds a very basic tree because it wants to be able to
> > > process very large documents in minimum memory. We certainly could
> > > generate a w3C DOM from this data (because we have a
> > > StreamingDOMBuilder which understands XMLSlurper GPath objects).
> > > However round tripping the data GPath tree -> DOM apply XPath
> > > expression -> GPath tree would be memory hungry and slow. So whilst
> > > it's doable I don't think its that useful.
> >
> >     W3C DOM. Gak!
> >
> >     Jaxen traverses it's document using an interator interface. You
> >     can implement a Navigator for whatever object model, as long at
> >     that model models an XML Infoset. (I sure someone has already
> >     created one for navigating Java Beans as XML.)
> >
> >     Saxon to has a node interface that can be wrapped around any
> >     DOM that models an XML Infoset.
> >
> >     Both use axis for navigation, rather than pointer navigation.
> >
> > > If you feel like giving it a try please  do - you can add an xpath
> > > function to the groovy.util.slurpersupport.GPathResult type via the
> > > "use" mechanism. I would be interested in seeing how such a scheme
> > > works - I may well be wrong about its utility.
> >
> >     XPath 1.0 and 2.0 are quite powerful, well-vetted, and fast.
> >
> >     These langauges are designed to be hosted. The suggested usage
> >     here is really quite apporpriate.
> >
> >     It really become analogous to the SQL libraries. A mixture of
> >     GPath, Builder and XPath, is very similiar to a mixture of
> >     GroovySQL, Builder and SQL.
> >
> > --
> > Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
> >
>
>
> --
> regards
> babelex
> http://babelex.blogspot.com/
> #OpenSource means free to innovate#
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Alan-19
* Dierk Koenig <[hidden email]> [2005-10-29 05:04]:

> cool!

> The user only has to put dom4j.jar on the cp.

> BTW: I started throwing all such jars in my ~/.groovy/lib.
> That's very convenient but may become a class-loading
> performance and versioning problem over time.
> Are there any ideas about supporting something like
> Ruby-Gems?

    I'd like so see a source based Groovy, uh, Rythyms.

    About the XPath thing. That would be an addition, an external
    library. GPath is very light. XPath is heavier (it is pretty
    much a language in itself).

--
Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Babelex
To use XPath in Dom4j you also need the jaxen jar on your cp

On 10/29/05, Alan <[hidden email]> wrote:

> * Dierk Koenig <[hidden email]> [2005-10-29 05:04]:
>
> > cool!
>
> > The user only has to put dom4j.jar on the cp.
>
> > BTW: I started throwing all such jars in my ~/.groovy/lib.
> > That's very convenient but may become a class-loading
> > performance and versioning problem over time.
> > Are there any ideas about supporting something like
> > Ruby-Gems?
>
>     I'd like so see a source based Groovy, uh, Rythyms.
>
>     About the XPath thing. That would be an addition, an external
>     library. GPath is very light. XPath is heavier (it is pretty
>     much a language in itself).
>
> --
> Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
>


--
regards
babelex
http://babelex.blogspot.com/
#OpenSource means free to innovate#
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

tugwilson
In reply to this post by Alan-19

On 28 Oct 2005, at 23:57, Alan wrote:

>   W3C DOM. Gak!
>
>     Jaxen traverses it's document using an interator interface. You
>     can implement a Navigator for whatever object model, as long at
>     that model models an XML Infoset. (I sure someone has already
>     created one for navigating Java Beans as XML.)
>
>     Saxon to has a node interface that can be wrapped around any
>     DOM that models an XML Infoset.
>
>     Both use axis for navigation, rather than pointer navigation.
>


The GPath object the XmlSlurper produces uses iterators so it might  
be possible to use these with Jaxen.


John Wilson
The Wilson Partnership
http://www.wilson.co.uk


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Alan-19
* John Wilson <[hidden email]> [2005-10-29 10:21]:

>
> On 28 Oct 2005, at 23:57, Alan wrote:
>
> >  W3C DOM. Gak!
> >
> >    Jaxen traverses it's document using an interator interface. You
> >    can implement a Navigator for whatever object model, as long at
> >    that model models an XML Infoset. (I sure someone has already
> >    created one for navigating Java Beans as XML.)
> >
> >    Saxon to has a node interface that can be wrapped around any
> >    DOM that models an XML Infoset.
> >
> >    Both use axis for navigation, rather than pointer navigation.
> >
>
>
> The GPath object the XmlSlurper produces uses iterators so it might  
> be possible to use these with Jaxen.

    I notice that I reversed myself, first saying JAXP, which would
    require building W3C DOM. Excuse me.

    Both Jaxen and Saxon have helper classes that generate other
    axis from a few common of axis. Ancestor from parent, decendent
    from child. So, yes. It should be very possible.

    Saxon is what I'd do first. It implements XPath 2.0, it is older
    and more mature, and very fast.

--
Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Alan-19
In reply to this post by Alan-19
* John Wilson <[hidden email]> [2005-10-28 12:38]:
>
> If you feel like giving it a try please  do - you can add an xpath  
> function to the groovy.util.slurpersupport.GPathResult type via the  
> "use" mechanism. I would be interested in seeing how such a scheme  
> works - I may well be wrong about its utility.

    John

    Pointers on the "use" mechanism. I'm not finding it in the
    places I normally look.

--
Alan Gutierrez - [hidden email] - http://engrm.com/blogometer/
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

tugwilson

On 30 Oct 2005, at 02:53, Alan Gutierrez wrote:

> * John Wilson <[hidden email]> [2005-10-28 12:38]:
>
>>
>> If you feel like giving it a try please  do - you can add an xpath
>> function to the groovy.util.slurpersupport.GPathResult type via the
>> "use" mechanism. I would be interested in seeing how such a scheme
>> works - I may well be wrong about its utility.
>>
>
>     John
>
>     Pointers on the "use" mechanism. I'm not finding it in the
>     places I normally look.

Yes it's a bit obscure:)

there's a use method on Object in DefaultGroovyMethods. This takes  
two parameters - a class or a list of classes and a closure. The  
class is treated like a mini DefaultGroovyMethods and the methods  
defined by this class are applied for the duration of the closure.  
The changes are only mode within the thread executing the use statement.

use (MyClass) {
Object o = new Object()

         o.myMethod() // this invokes the myMethod defined in MyClass
}

so MyClass will define a static method with the signature voidmyMethod
(Object)


John Wilson
The Wilson Partnership
http://www.wilson.co.uk


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Some groovy community help please

Babelex
One of the other advantages of Saxon (8.5.x) is you get XQuery for free!!

Now not everybody gets XQuery, but it's a really usefull solution for
so many problems where a database is overkill.

If XMLSlurper could also support Xquery as well as XPath it would
really start moving XML into first class within the groovy language.

This conbination would allow simple xml object stores based on XML
files, which can be cache in memeroy if needed. And is absolutely
great for simple web apps that need xml storage.

Just a thought

On 10/30/05, John Wilson <[hidden email]> wrote:

>
> On 30 Oct 2005, at 02:53, Alan Gutierrez wrote:
>
> > * John Wilson <[hidden email]> [2005-10-28 12:38]:
> >
> >>
> >> If you feel like giving it a try please  do - you can add an xpath
> >> function to the groovy.util.slurpersupport.GPathResult type via the
> >> "use" mechanism. I would be interested in seeing how such a scheme
> >> works - I may well be wrong about its utility.
> >>
> >
> >     John
> >
> >     Pointers on the "use" mechanism. I'm not finding it in the
> >     places I normally look.
>
> Yes it's a bit obscure:)
>
> there's a use method on Object in DefaultGroovyMethods. This takes
> two parameters - a class or a list of classes and a closure. The
> class is treated like a mini DefaultGroovyMethods and the methods
> defined by this class are applied for the duration of the closure.
> The changes are only mode within the thread executing the use statement.
>
> use (MyClass) {
> Object o = new Object()
>
>          o.myMethod() // this invokes the myMethod defined in MyClass
> }
>
> so MyClass will define a static method with the signature voidmyMethod
> (Object)
>
>
> John Wilson
> The Wilson Partnership
> http://www.wilson.co.uk
>
>
>


--
regards
babelex
http://babelex.blogspot.com/
#OpenSource means free to innovate#
Reply | Threaded
Open this post in threaded view
|

RE: [groovy-user] Some groovy community help please

Dierk König
> Now not everybody gets XQuery [..]

Yep, me for example.

It's a sidetrack, but what does XQuery better than XPath?

cheers
Mittie
123