jastrachan | 29 Mar 20:11 2004
Picon

Re: MarkupBuilder confusion


On 29 Mar 2004, at 17:17, Shakeel Mahate wrote:

> The MarkupBuilder uses "magic" to handle invocations of methods not
> implemented by the class.
>
> Temp = new MarkupBuilder()
> Temp.root() {
>   Temp.node1() {
>     Temp.node2() {
>     }
>   }
> }
>
> This generates
> <root>
>   <node1>
>      <node2/>
>   </node1>
> </root>
>
> Is the "magic" implemented by catching Method Not Implemented 
> exceptions?
>
> I have found that the MarkupBuilder gets confused very easily when I 
> try to
> utilize methods or closures or any sort of programming idioms within 
> them.
>
> For example
>
> Class Junk {
>   temp = new MarkupBuilder()
>
>   void AddSpecialNodes(name) {
>     temp->createNode(name, "Some special value")
>   }
>
>   Temp.root() {
>      AddSpecialNodes('xyz')
>      Temp.node1() {
>      }
>   }
> }
>
> Groovy barfs on AddSpecialNodes.  It also gets confused on

That looks like a bug

>   [1..10].each { it | temp->createNode(it) }
>
> also fails.
>
> Are these growing pains?

They could be. Though I had trouble reproducing your errors...

1> import groovy.xml.MarkupBuilder
2> temp = new MarkupBuilder()
3> go

1>   [1..10].each { it | temp->createNode(it) }
2> go
<createNode>1..10</createNode>
1> (1..10).each { it | temp->createNode(it) }
2> go

<createNode>1</createNode>
<createNode>2</createNode>
<createNode>3</createNode>
<createNode>4</createNode>
<createNode>5</createNode>
<createNode>6</createNode>
<createNode>7</createNode>
<createNode>8</createNode>
<createNode>9</createNode>
<createNode>10</createNode>

How does it fail for you?

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

Gmane