Wednesday, March 28, 2007

Parsing JMemorize Documents with Groovy

Groovy makes a lot of things absolutely very easy. One of them is xml parsing.

I use JMemorize for learning new programming libraries like Wicket and Groovy. But I want to import my flash cards into Keynote. So I needed to parse xml documents that JMemorize uses for storing the cards.

It is not a big deal parsing xml documents. But Groovy makes it much easier. I put my code here to show Groovy's easiness and maybe some JMemorize users may benefit.

def lesson = new XmlParser().parse(new File('resources/Java.jml'))
def cards = lesson.Category.Category.grep{it.'@name' == 'Groovy'}.Deck.Card
output = new File('resources/jmemorize.txt')
def counter = 0
for(card in cards) {
output << "Soru $counter:\n\n" << card.'@Backside' << '\n----\nYanıtı:\n' << card.'@Frontside' << '\n====\n'


Eelco Hillenius said...

JMemorize is a neat little app!

james Dean said...

This is certainly one of the most valuable posts. Great tips from beginning till end. Lots of suggestions for me and for people. Superb work

small business IT Support