|
Re: GPath, and Builder synergy: msg#00088lang.groovy.user
On Tue, Oct 05, 2004 at 10:56:56AM +0100, John Wilson wrote: > I have been playing with new ways of using Builders and GPath in the > sandbox (XMLSlurper and StreamingMarkupBuilder). I recently enhanced > StreamingMarkupBuilder so that it would understanfdGPath expressions > dump subtrees defined by a GPath expression directly into the output of > the builder (This was covered by my XMLOpen presentation > http://groovy.codehaus.org/Articles). > > It strikes me that if we make GPath understand Builders we could have a > very powerful way of specifying complex transforms on documents. > > My idea is to allow closures to be assigned to nodes specified by a > GPath expression. The result of this operation is that the node and all > subnodes are replaced by the result of running the closure as a Builder > closure with the original subnode as its parameter. The builder would > create whatever underlying representation of the document was being > used by the GPath implementation. > > Perhaps an example would help: > > given the document > > <root> > <node> > <someInterestingData attr = '1'>my <b>data</b></someInterestingData> > <someBooringData>don't read this</someBooringData > > </node> > </root> > > > the GPath statement > > node = {data(myAttr:it. someInterestingData['@attr']) { > mkp:yield it. someInterestingData.contents() > } > } > > would produce > > <root> > <node> > <data myAttr = '1'>my <b>data</b></data> > </node> > </root> > > > I'm not quite sure about the notation. Perhaps node.transform{ ....} > would be clearer? > > Anybody interested in using Groovy in this way? > > John Wilson > The Wilson Partnership > http://www.wilson.co.uk Cited the whole mail intentionally, as I was suprised that there was no answer to it. I would be really happy to use this black magic. The syntax is OK, I studied the GPath statement only for ten minutes, and then understood what's going on. incze
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | xml with namespaces, Valenta, Jakub \(GE Healthcare\) |
|---|---|
| Next by Date: | Return from the Closure, 任立新 |
| Previous by Thread: | GPath, and Builder synergy, John Wilson |
| Next by Thread: | Re: Evaluating dynamic GPath, Daniel Serodio |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |