GPath on a w3c Document

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GPath on a w3c Document

Mike Butler-4

Hi folks,

        Given a pre-existing w3c Document object is there some standard way  
of using GPath notation on it?  I just started rolling my own  
implementation, but it occurred to me that I should check first to  
see if there is an official way of doing this.

        Thanks,

        Mike.

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: GPath on a w3c Document

Dierk König
use the DomCategory and GPath

cheers
Mittie

> -----Original Message-----
> From: mike [mailto:[hidden email]]
> Sent: Freitag, 12. Mai 2006 22:29
> To: [hidden email]
> Subject: [groovy-user] GPath on a w3c Document
>
>
>
> Hi folks,
>
> Given a pre-existing w3c Document object is there some
> standard way  
> of using GPath notation on it?  I just started rolling my own  
> implementation, but it occurred to me that I should check first to  
> see if there is an official way of doing this.
>
> Thanks,
>
> Mike.
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: GPath on a w3c Document

Dierk König
from chapter 11:

Dealing with child nodes and attributes as in Listing 11.2 doesn't feel very
groovy either.
Therefore, Groovy provides a DOMCategory that we can use for simplified
access. With this
help, we can index child nodes via the subscript operator or via their node
name. We can refer to
attributes by getting the '@attributename' property.

use(groovy.xml.dom.DOMCategory){
    assert 'plan' == plan.nodeName
    assert 'week' == plan[1].nodeName
    assert 'week' == plan.week.nodeName
    assert '8' == plan[1].'@capacity'
}

hope that helps
Mittie

> -----Original Message-----
> From: Dierk Koenig [mailto:[hidden email]]
> Sent: Freitag, 12. Mai 2006 23:52
> To: [hidden email]
> Subject: RE: [groovy-user] GPath on a w3c Document
>
>
> use the DomCategory and GPath
>
> cheers
> Mittie
>
> > -----Original Message-----
> > From: mike [mailto:[hidden email]]
> > Sent: Freitag, 12. Mai 2006 22:29
> > To: [hidden email]
> > Subject: [groovy-user] GPath on a w3c Document
> >
> >
> >
> > Hi folks,
> >
> > Given a pre-existing w3c Document object is there some
> > standard way
> > of using GPath notation on it?  I just started rolling my own
> > implementation, but it occurred to me that I should check first to
> > see if there is an official way of doing this.
> >
> > Thanks,
> >
> > Mike.
> >
> >

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GPath on a w3c Document

Mike Butler-4
In reply to this post by Dierk König
Thanks Dierk,

        however, I need to do this on the Java side, and I'm not sure how I  
would get the DomCategory to fit in that case.

        In my particular situation I'm using Groovy as the scripting  
language for my existing Java App.  I can see how in a groovy script  
I could do "use(){}"  however, I'd like to keep things really  
straightforward for my scripters.  I'd really like to be able to just  
bind the Document root so that the scripters can walk it via a very  
simple syntax ( GPath ) and without them having to know enough to add  
a category first.

        Is it possible to add the Category somehow on the Java side before  
it gets to the script?

        Thanks again for the help,

        Mike.

       

On 12 May 2006, at 22:51, Dierk Koenig wrote:

> use the DomCategory and GPath
>
> cheers
> Mittie
>
>> -----Original Message-----
>> From: mike [mailto:[hidden email]]
>> Sent: Freitag, 12. Mai 2006 22:29
>> To: [hidden email]
>> Subject: [groovy-user] GPath on a w3c Document
>>
>>
>>
>> Hi folks,
>>
>> Given a pre-existing w3c Document object is there some
>> standard way
>> of using GPath notation on it?  I just started rolling my own
>> implementation, but it occurred to me that I should check first to
>> see if there is an official way of doing this.
>>
>> Thanks,
>>
>> Mike.
>>
>>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: GPath on a w3c Document

Dierk König
of course.

There are multiple integration options. E.g. all Groovlets are
Scripts that run in the scope of a ServletCategory.
Have a look at groovy.servlet.GroovyServlet.
From the Java side, CategorySupport does the job.

Other options are providing a common base class for all
evaluated Scripts in the GroovyShell or simply wrapping the
code into a use(){} String before evaluation.

cheers
Mittie

> -----Original Message-----
> From: mike [mailto:[hidden email]]
> Sent: Samstag, 13. Mai 2006 0:42
> To: [hidden email]
> Subject: Re: [groovy-user] GPath on a w3c Document
>
>
> Thanks Dierk,
>
> however, I need to do this on the Java side, and I'm not
> sure how I  
> would get the DomCategory to fit in that case.
>
> In my particular situation I'm using Groovy as the scripting  
> language for my existing Java App.  I can see how in a groovy script  
> I could do "use(){}"  however, I'd like to keep things really  
> straightforward for my scripters.  I'd really like to be able to just  
> bind the Document root so that the scripters can walk it via a very  
> simple syntax ( GPath ) and without them having to know enough to add  
> a category first.
>
> Is it possible to add the Category somehow on the Java side before  
> it gets to the script?
>
> Thanks again for the help,
>
> Mike.
>
>
>
> On 12 May 2006, at 22:51, Dierk Koenig wrote:
>
> > use the DomCategory and GPath
> >
> > cheers
> > Mittie
> >
> >> -----Original Message-----
> >> From: mike [mailto:[hidden email]]
> >> Sent: Freitag, 12. Mai 2006 22:29
> >> To: [hidden email]
> >> Subject: [groovy-user] GPath on a w3c Document
> >>
> >>
> >>
> >> Hi folks,
> >>
> >> Given a pre-existing w3c Document object is there some
> >> standard way
> >> of using GPath notation on it?  I just started rolling my own
> >> implementation, but it occurred to me that I should check first to
> >> see if there is an official way of doing this.
> >>
> >> Thanks,
> >>
> >> Mike.
> >>
> >>
Loading...