First attempt was blocked by the mailing list for being too long, so here’s the trimmed version.  This works in IE also:

 

function xmlToHash(el) {

  Element.cleanWhitespace(el);

  if ((el.attributes && el.attributes.length > 0)

   || (el.hasChildNodes() && el.childNodes[0].nodeType == 1)) {

    var localHash = {};

    if (el.attributes && el.attributes.length >= 1) {

      $A(el.attributes).each(function (attr) { localHash[attr.nodeName] = [attr.nodeValue]; });

    }

    $A(el.childNodes).each(function (el) { xmlToHashElement(localHash, el); });

    for (attr in localHash) {

      if (localHash[attr].length == 1) {

        localHash[attr] = localHash[attr][0];

      }

    }

    return localHash;

  }

  else {

    return el.textContent || el.innerText || el.text || '';

  }

}

 

function xmlToHashElement (hash, el) {

  if (el.nodeType == 2) {

    hash[el.localName] = [ el.textContent || el.innerText || el.text || '' ];

  }

  else {

              var key = el.tagName;

              if (hash[key]) {

                hash[key].push(xmlToHash(el));

              }

              else {

                hash[key] = [ xmlToHash(el) ];

              }

  }

}

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gregory Hill
Sent: Friday, March 17, 2006 11:27 AM
To: rails-spinoffs@lists.rubyonrails.org
Subject: RE: [Rails-spinoffs] good _javascript_ xml parser

 

Oops… it doesn’t work at all in IE.  Friggin IE.

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to