Language E4X
(Generating the song using E4X and Rhino)
| Date: | 04/07/07 |
| Author: | Ray Djajadinata |
| URL: | http://rayfd.wordpress.com/ |
| Comments: | 0 |
| Info: | http://www.ecma-international.org/publications/standards/Ecma-357.htm |
| Score: |
// get the lyrics page. Rhino readUrl() method is particularly
// convenient.
var rawLyrics = readUrl("http://99-bottles-of-beer.net/lyrics.html");
// the html lyrics page (http://99-bottles-of-beer.net/lyrics.html)
// is not well-formed, so we have to replace <br> with <br/>
var wellFormedRawLyrics = rawLyrics.replace(/<br>/gi, "<br/>");
var xmlLyrics = new XML(wellFormedRawLyrics);
// set the default namespace for convenience--don't hardcode
default xml namespace = xmlLyrics.namespace();
// First, we look for any elements in the page that contains an element
// whose text starts with "99 bottles of beer".
var songVerses = xmlLyrics..*.(/^99 bottles of beer/.test(p.text()));
// Then we print each verse, adding newlines as necessary
for each(var verse in songVerses.children()) {
var verseText = verse.text().toString().replace("\.", ".\n");
print(verseText + "\n");
}
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments