Request.HTML

Sends HTML code to backend updates target div and executes <script>

HTML

<?xml version="1.0"?>
<!DOCTYPE compactdiscs SYSTEM "cds.dtd">
<compactdiscs>
  <compactdisc>
    <artist type="individual">Frank Sinatra</artist>
    <title type="individual">Inn The Wee Small Hourss</title>
   <tracks>
      <track>In The Wee Small Hours</track>
      <track>Mood Indigo</track>
      <track>Glad To Be Unhappy</track>
      <track>I Get Along Without You Very Well</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
  <compactdisc>
    <artist type="band">The Offspring</artist>
    <title numberoftracks="5">Americana</title>
   <tracks>
      <track>Welcome</track>
      <track>Have You Ever</track>
      <track>Staring At The Sun</track>
      <track>Pretty Fly (For A White Guy)</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
</compactdiscs>

CSS

body {
    font-family: Helvetica, Sans, Arial;
}
p {
    padding: 10px;
}

JavaScript

/*
---
name:         XMLReader
description: Provides an easy way to read XML files while converting it's content to an Object.

license: MIT-style

authors:
- Ciul

requires:
- core/1.3    : *

provides: [XMLRequest, XML2Object]

...
*/

/*********************************** XML to Object Converter **********************************/

var XML2Object = new Class({
    
    Implements: Events,
    /*    Events:
        complete: $empty,
    */
    
    /* Global variables */
    xml: null,
    text: null,
    xmlObj: {},
    xmlurl: null,
    root: null,
    
    /* Initialize */
    initialize: function(xmlurl) {
        xmlurl = (xmlurl != undefined && typeOf(xmlurl) == 'string')? xmlurl : '';
        if(!xmlurl.contains('xml','.')) {
            xmlurl = xmlurl + '.xml';
        }
        this.xmlurl = xmlurl;
        var xmlRequest = new XMLRequest(xmlurl).addEvent('success', function(text, xml) {
                   // debugger;
this.text = text;
            var t= new Date().getTime();
                this.xml = xml;
            this.root = this.get_rootNode();
            this.xmlObj = this._recursive_traverse(this.root);
            //console.log('...');
            //console.log(this.xmlObj);
            
                                                         this.complete();
                                                         console.log('execution time ',(new Date().getTime()) - t);
        }.bind(this)).send();
    },
    
    /********************** XML OBJECT methods **********************/
    _recursive_traverse: function(node) {
        
        var attributes = new Object();
        if(this.has_attributes(node)) {
            Array.each(this.get_attributes(node), function(attribute, index) {
                attributes[this.get_name(attribute)] = this.get_value(attribute);
            }, this);
        }
        
        var childNodes = new Array();
        if(this.has_childNodes(node)) {
            Array.each(this.get_childElements(node),...