jastrachan | 29 Apr 22:23 2004
Picon

Re: xml document to node (object)

On 29 Apr 2004, at 19:32, Richard Monson-Haefel wrote:
> How do you handle namespaces with GPath?

Namespaces are hard. They're hard in XPath too.

> I can't peruse my XML because each element is assigned a namespace 
> prefix.

Ah we should probably fix the methods on Node to handle GPath across 
local variable names - its a bug, we've just not tested for that 
before. Could you create a JIRA issue for this please?

To be totally precise with namespaces we'd end up using QName objects.

http://groovy.codehaus.org/apidocs/groovy/xml/QName.html

QName element = new QName("http://w3c.org/whatever/schema/thingy", 
"element")

elements = schema[element]

etc.

so rather than using property access we could use subscript operators

text = html[body][h1][0]

not as neat though.

Another thing I wondered about was having a namespace aware facade. 
e.g. if you want to navigate though an XML structure using a specific 
namespace you could 'project' things back to a non-namespaced look & 
feel.

e.g.

myDoc = html.namespace("http://www.whatever/my/namespace/URI/is")

// all names in the namespace appears as normal properties now
text = myDoc.body.h1[0].text()

James
-------
http://radio.weblogs.com/0112098/

Gmane