Sam Collett wrote:
> On 02/10/06, Mark Gibson <[EMAIL PROTECTED]> wrote:
>> Hello,
>> I've search high and low, but can't find a method of serializing XML
>> with jQuery. Have I missed something, or should I start writing a
>> new plugin? ($.fn.serializeXML)
>>
>> I know that firefox has XMLSerializer(), any ideas for IE, Safari,
>> Opera? Maybe just a hand coded JS serializing routine?
> 
> I don't think there is any way of serializing XML in jQuery without
> resorting to a plugin (I don't know of any plugins that can do this).
> 
> I think a multi-purpose serializer would be good:
> JS Object <--> XML <--> JSON <--> JS Object

I was specifically thinking of just serializing DOM objects to strings,
anything beyond that requires some kind of mapping.

Here's a simple implementation using the XMLSerialize object:

$.fn.serializeXML = function () {
        var out = '';
        if (typeof XMLSerializer == 'function') {
                var xs = new XMLSerializer();
                this.each(function() {
                        out += xs.serializeToString(this);
                });
        } else {
                // TODO: Find another serializer, or manually serialize
        }
        return out;
};

This will need to be fleshed out for other browsers.

Does anyone know of native serialization methods in IE, Safari, Opera?
or do any of these support XMLSerialize()?

- Mark Gibson

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to