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 ==
e it doesn't handle every possible scenario,
> but it's a decent start. You need to load prototype to use this, btw.
>
>
>
> Greg
>
>
>
>
>
>
>
>
>
>
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
>
Oops… it doesn’t work at all
in IE. Friggin IE.
From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gregory
Hill
Sent: Friday, March 17, 2006 11:20
AM
To: rails-spinoffs@lists.rubyonrails.org
Subject: RE: [Rails-spinoffs] good
_javascript_ xml parser
It’s pr
It’s pretty quick-and-dirty, but
this is my first attempt.
function xmlToHash(el) {
Element.cleanWhitespace(el);
if (el.hasAttributes() ||
(el.hasChildNodes() && el.childNodes[0].nodeType == 1)) {
var localHash = {};
if (el.hasAttributes
&& el.attributes.length >= 1) {
This might not be practical for you, but the google maps api has an xml parser that uses a native xml parser if the browser has one and a _javascript_ parser if the browser doesn't.http://www.google.com/apis/maps/documentation/#GXml_code_Also, just found http://xmljs.sourceforge.net/ Tom Riley
Hmm… that is a pretty cool class. I
was hoping more for something that you didn’t need to know what the tag
names were, it would just create a hierarchy that you could drill down into
easily, but if I get stuck, this is a good backup.
Greg
From: [EMAIL PROTECTED]
[mailto:
Maybe this would help you :)
Thank you,Mandy.
p.s. I have not written this. I got this from some site
long time back.
XMLParser = Class.create();Object.extend(XMLParser.prototype, { initialize: function(xmlObj) {this.xmlObj = xmlObj;this.root = xmlObj.documentElement; }, list
If you are only using for server-client communications, you might
consider JSON. I needed something very basic as well, but just decided
to go with JSON instead of XML since it has less markup and is just
plain simpler. Using XML with prototype was more trouble than it was
worth for me. Usage i
Good point, I hadn’t thought of that
‘cause the project I was needing it for didn’t use them. I’ll
have to think about that for a bit.
Greg
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ryan Gahl
Sent: Friday, March 17, 2006 8:48
AM
To: rails-spinoffs@lis
> If not, I’m
gonna build one.
Cool, make sure it can handle both elements
and attributes. For instance, how would your example be different if my XML doc
was…
The information transmitted in this electronic mail is intended only for the person or entity to which it
Anyone know of a _javascript_ function that will take an xml
document and turn it into an associative array?
Basically it would take something like this:
1
Bob
2
John
And turn it into something like this:
{
itemList: [
{
id: 1,
name: ‘Bob’
},
{
id: 2,
name:
11 matches
Mail list logo