XMLNodeSimple = function(xml) {
  this._attributes= [];
  this._elements= [];
  this._name = xml.nodeName.split('-').join('_');
  this._text= '';
  this._value= '';

  var txt = "";
  var kid, simplekid, nodename, tmp;

  for (var i=0; i<xml.childNodes.length; i++) {
    kid = xml.childNodes[i];
    switch (kid.nodeType) {
      case 1: // elem
        simplekid = new XMLNodeSimple(kid);
        nodename = kid.nodeName.split('-').join('_');
        this._elements.push({name: nodename, value: simplekid});
        switch (typeof this[nodename]) {
          case 'object':
            this[nodename].push(simplekid);
            break;
          case 'undefined':
            this[nodename] = [simplekid];
            break;
        }
        break;
      case 3: // text
      case 4: // CDATA
        txt += kid.nodeValue;
        break;
      default:
    }
  }
  for (i=0; i<this._elements.length; i++) {
    x = this._elements[i];
    if (this[x.name].length == 1) {
      this[x.name] = this[x.name][0];
    }
  }

  // attributes
  // ie wtf?
  /*
  for (kid in xml.attributes) {
    simplekid = xml.attributes[kid];
    nodename = kid.split('-').join('_');
    this._attributes.push({name: nodename, value: simplekid});
    this["$" + nodename] = simplekid;
  }
  */

  this._text = txt;
  this._value = txt;
  this._xml = xml;
}
XMLNodeSimple.prototype.toString = function() {
  var i;
  var s = /*this._name + ": " + */this._text;
  //s = '';
  if (this._attributes.length) {
    s += "\n";
    //s += "\n\tAttributes:\n";
    for (i=0; i < this._attributes.length; i++) {
      x = this._attributes[i];
      s += "\t$" + x.name + ": " + x.value + "\n";
    }
  }
  if (this._elements.length) {
    s += "\n";
    //s += "\n\tElements:\n";
    for (i=0; i < this._elements.length; i++) {
      x = this._elements[i];
      s += "- " + x.name + "\n";
      s += "\t" + x.value.toString().split("\n").join("\n\t") + "\n";
    }
  }
  return s;
}
