Hi,

> $.fn.serializeXML = function () {
>       var out = '';
>       if (typeof XMLSerializer == 'function') {
>               var xs = new XMLSerializer();
>               this.each(function() {
>                       out += xs.serializeToString(this);
>               });
>       } else if (this[0] && this[0].xml != 'undefined') {
>               this.each(function() {
>                       out += this.xml;
>               });
>       }
>       return out;
> };

Maybe this could make the code simpler:

if( typeof XMLSerializer != 'function' ) {
        XMLSerializer = function() {};
        XMLSerializer.prototype.serializeToString = function(elm) {
                return eml.xml;
        }
}

Then you just need

$.fn.xml = function () {
        var out = '';
        var xs = new XMLSerializer();
        this.each(function() {
                out += xs.serializeToString(this);
        });
        return out;
};

Advantages:
1. Your code checks for XMLSerializer with every call. Mine only once.
2. You can add another check to see if there is a .xml-Property. If that is 
not available you can have your own (slower) serializer-function that simply 
traverses the DOM.
3. By resembling the XMLSerializer-API (not complete now) you can make third 
party code work that needs XMLSerializer.

BTW.: With such a simple function in each() you might also consider to use a 
normal for-loop:
for( var i = 0; i < this.length; i++ ) out += xs.serializeToString(this[i]);

That doesn't look so fancy, but it should be faster.

Christof

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

Reply via email to