jastrachan | 30 Apr 17:01 2004
Picon

Re: xml document to node (object)

On 30 Apr 2004, at 15:42, Joe Germuska wrote:
> I think it would be groovy for Node to have some bean property to get 
> its value.  Is there a reason why "value()" isn't "getValue()" and 
> "text()" -> "getText()" ?

To ensure that 'value' and 'text' don't conflict with elements called 
'value' and 'text'.

e.g.

<foo>
whatnot
<value>133</value>
<text>hello</text>
</foo>

we can now do

     foo.text
     foo.value

to return the child elements, and

     foo.value() to get the list of children  = [String, Node, Node]
     foo.text() to return the text content of foo = "whatnot"

> true, the difference between page.Body.h1.text() and page.Body.h1.text 
> isn't that great...  but it seems more in the spirit of the language.

Remember that there's a difference between Groovy-the-language and the 
single Node class which is trying to represent a simple XML DOM-ish 
model (in 1 class! :-). We can implement many different navigation 
models in Groovy.

We could transform XML into an object model in many different ways with 
different mechanisms. e.g. disallow elements called 'value' and 'text' 
and so forth. What I tried to do with Node was preserve XML InfoSet 
semantics that people who work with XML will be used to in a clean 
unambigious way.

So I've used property access to navigate elements by name, and methods 
like value() and text() and attribute() and so forth to navigate in 
other axes (children, text value, attributes and the like).

But like I said to Richard, folks could write a helper class to remove 
the XML semantics and make everything look like maps of values - though 
there will be some XML cases that don't work (like attributes & 
elements with the same name, like elements called 'text' or 'value' 
etc).

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

Gmane