[linux-l] Re: groovy

Ivan F. Villanueva B. iv at artificialidea.com
Fr Aug 25 17:19:54 CEST 2006


Am Fr, Aug 25, 2006 01:50:06 +0200, David Hansen schrieb:
> On Thu, 24 Aug 2006 21:15:24 +0200 Ivan F. Villanueva B. wrote:
> 
> > Hier ein Beispiel in Groovy, um XML zu generieren. Gibt es bessere Alternativen?
> >
> >     import groovy.xml.MarkupBuilder;
> >     myXMLDoc = new MarkupBuilder()
> >     myXMLDoc.library {
> >        section(id:"Programming") {
> >          book(title:"Java? Groovy!", author:"Duke McCoffee", "book 1")
> >          book("book 2", title:"The art of hacking code", author:"Uber Hacker")
> >        }
> >     }
> >
> > Ausgabe:
> >
> >     <library>
> >       <section id='Programming'>
> >         <book title='Java? Groovy!' author='Duke McCoffee'>book 1</book>
> >         <book title='The art of hacking code' author='Uber Hacker'>book 2</book>
> >       </section>
> >     </library>
> >
> > Ich finde es genial.
> 
> Du bist ziemlich einfach zu beeindrucken,

das Stimmt.

> wenn du ein einfaches Zusammenfügen von Strings als "genial" empfindest.

Das Stimmt nicht. Jemand hat sich eine Syntax ausgedacht, die fast genauso
aussieht, wie ihre Semantic. Das ist die Genialität.

Ein anderes Beispiel:

    class Book {
        public title
        public author
    }

    myXMLDoc.library {
        section(id:"Programming") {
            books.each() {b ->
                book(title: b.title, author: b.author)
            }
        }
    }

books ist eine Samlung von Objekten der Classe Book

Output:

<library>
  <section id='Programming'>
    <book title='java' author='author1' />
    <book title='groovy' author='author2' />
    <book title='python' author='author3' />
    ...
  </section>
</library>

Mehr Beispiele in:
http://www.artificialidea.com/author/wiki/doku.php?id=groovy:xml

-- 
Ivan F. Villanueva B.
A.I. library:   http://www.artificialidea.com
<<<          The European Patent Litigation Agreement (EPLA)          >>>
<<<            will bring Software patents by the backdoor            >>>
<<<  http://www.no-lobbyists-as-such.com/florian-mueller-blog/epla/   >>>
<<<                     http://wiki.ffii.de/EplaEn                    >>>



Mehr Informationen über die Mailingliste linux-l