E4X With Prototype.js

<html>
<head>
<!– linking prototype.js to this html page –>
<script type=”text/javascript” src=”http://script.aculo.us/prototype.js”> </script>

<!–  e4x=1 should be defined like that –>
<script type=”text/javascript ; e4x=1″>

<!– This js function is called if “click me”  on the main web page is clicked–>
function loadXML () {
var xmlMusic=new XML() ;

<!– xml definition–>
xmlMusic =
<mp3>
<music genre=”classical”>
<artist>Ludwig van Beethoven</artist>
<song>Fifth Symphony</song>
</music>
<music genre=”jazz”>
<artist>Grover Washington, Jr.</artist>
<song>The Best Is Yet to Come</song>
</music>
<music genre=”classical”>
<artist>Johann Sebastian Bach</artist>
<song>Double Concerto in D- for Two Violins</song>
</music>
<music genre=”jazz”>
<artist>Dave Brubeck</artist>
<song>Take Five</song>
<song>Truth Is Fallen</song>
</music>
<music genre=”classical”>
<artist>Johannes Brahms</artist>
<song>Piano Sonata No. 1 in C major</song>
</music>
</mp3>

<!– selecting “Ludwig van Beethoven” and saving to var xmlMusicShow–>
var xmlMusicShow = xmlMusic.music[0].artist;

<!– inserting “Ludwig van Beethoven” to div “showXML” –>
document.getElementById(“showXML”).innerHTML = xmlMusicShow;

<!– showing that hidden div “showXML” with new value “”Ludwig van Beethoven” –>
<!– Using prototype.js feature $(“someDivID”)  –>
$(‘showXML’).show();
}

</script>
</head>

<body>
<p onclick=”loadXML();” > click me </p>

<div id=”showXML” style=”display:none;”>

</div>
</body>
</html>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.