Re: [jQuery] New plugin: toXML (XML serializer)
Hi John, My objections are mostly from a philosophical standpoint. Since it may sometimes return valid xml and sometimes return a doc fragment, what can you do with it? You can't load it in a document, you can't post it to a web service... you'd have to manually parse it to figure out what it includes and therefore what it could be used for. I think it could be improved if it wrapped its results in its own root element or was renamed to .toXmlMarkup(). Tony Collins -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Resig Sent: Thursday, October 05, 2006 8:20 PM To: jQuery Discussion. Subject: Re: [jQuery] New plugin: toXML (XML serializer) Tony - It's not, necessarily, implied that this plugin will return valid XML for an entire XML Document - instead, it's returning valid XML for an XML Document Fragment - which is perfectly "ok". I mean, you can't expect $([ item1, item2 ]).toXML() to give you a valid XML document - and forcefully wrapping itself seems foolhardy. If it was so much of a concern, maybe there could be a .toXMLDocument() which returned a valid XML document instead of just a fragment. --John On 10/5/06, Antonio Collins <[EMAIL PROTECTED]> wrote: > I'm sorry but I don't agree with this plugin's name or usage. It > simply appends multiple valid xml together so the result could be > invalid xml and include multiple root elements. In my opinion, the > result of any method named .toXML() should be valid xml and the > following tests should result in valid XML documents. > > IE: domDoc.loadXML( $([ item1, item2 ]).toXML() ); > FF: (new DOMParser()).parseFromString( $([ item1, item2 ]).toXML(), > "text/xml" ); > > Tony Collins > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Christof Donat > Sent: Thursday, October 05, 2006 10:02 AM > To: jQuery Discussion. > Subject: Re: [jQuery] New plugin: toXML (XML serializer) > > Hi, > > > The thing is, the main use case for a toXML() call is to send XML > > data via an ajax request. > > Well, I could imagine that there may be other usecases as well, like > doing search and replace operations on the string representation of a > XML which is reparsed afterwards. It was just a joke, but you may look at that "use case" > > which could be usefull for XML-Data as well: > > http://dean.edwards.name/weblog/2006/07/erlaubt/#comment7262 > > > The duration of the request greatly overshadows any optimisation > > that could be applied to toXML. > > Well, there are also use cases, where you can assume a really fast > network connections (inhouse with 1GB-Ethernet e.g.) and thus work > with huge datasets on the client side. Then suddenly the time, the > client and server need to process the request becomes the dominating factor. > > I think that jQuery could also be really usefull for Applications > using XULrunner (I haven't tried yet) and thus there are many other > use cases like e.g. working with RDF-Data, etc. - OK, we don't need to > emulate XMLSerializer then. > > > Also, I don't think it is a good idea to attempt to implement an > > XMLSerializer object for the sake of it, especially when the full > > interface isn't being implemented > > You are right here of course. I was too lazy to look for the > XMLSerializer-interface and see if the other functions can also be > simulated so easy. > > > As a rule I live by the KISS principle, and never optimise code > > unless it becomes a bottleneck, and then only do so under profiling conditions. > > Well, KISS is an optimization strategy :-) Most of the time code is > fast when it is simple, but "most of the time" is not "always". > > Christof > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > -- John Resig http://ejohn.org/ [EMAIL PROTECTED] ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
The project has moved to sourceforge: http://innerdom.sourceforge.net/ I think, this work can improve your plugin. Mathias 2006/10/5, Mathias Bank <[EMAIL PROTECTED]>: > Oh, that's interesting. Perhaps this page will help you: > > http://simon-kuehn.de/projekte_innerdom.html (via > http://www.strohhalm.org/forum/index.php?action=viewTopic&topic=1516) > > Mathias > > 2006/10/5, Mark Gibson <[EMAIL PROTECTED]>: > > Hi, > > I've submitted the XML serializer plugin to the wiki: > > > > http://jquery.com/docs/Plugins/toXML/ > > > > - Mark Gibson > > > > ___ > > jQuery mailing list > > discuss@jquery.com > > http://jquery.com/discuss/ > > > ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Tony - It's not, necessarily, implied that this plugin will return valid XML for an entire XML Document - instead, it's returning valid XML for an XML Document Fragment - which is perfectly "ok". I mean, you can't expect $([ item1, item2 ]).toXML() to give you a valid XML document - and forcefully wrapping itself seems foolhardy. If it was so much of a concern, maybe there could be a .toXMLDocument() which returned a valid XML document instead of just a fragment. --John On 10/5/06, Antonio Collins <[EMAIL PROTECTED]> wrote: > I'm sorry but I don't agree with this plugin's name or usage. It simply > appends multiple valid xml together so the result could be invalid xml and > include multiple root elements. In my opinion, the result of any method > named .toXML() should be valid xml and the following tests should result in > valid XML documents. > > IE: domDoc.loadXML( $([ item1, item2 ]).toXML() ); > FF: (new DOMParser()).parseFromString( $([ item1, item2 ]).toXML(), > "text/xml" ); > > Tony Collins > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Christof Donat > Sent: Thursday, October 05, 2006 10:02 AM > To: jQuery Discussion. > Subject: Re: [jQuery] New plugin: toXML (XML serializer) > > Hi, > > > The thing is, the main use case for a toXML() call is to send XML data > > via an ajax request. > > Well, I could imagine that there may be other usecases as well, like doing > search and replace operations on the string representation of a XML which is > reparsed afterwards. It was just a joke, but you may look at that "use case" > > which could be usefull for XML-Data as well: > > http://dean.edwards.name/weblog/2006/07/erlaubt/#comment7262 > > > The duration of the request greatly overshadows any optimisation that > > could be applied to toXML. > > Well, there are also use cases, where you can assume a really fast network > connections (inhouse with 1GB-Ethernet e.g.) and thus work with huge > datasets on the client side. Then suddenly the time, the client and server > need to process the request becomes the dominating factor. > > I think that jQuery could also be really usefull for Applications using > XULrunner (I haven't tried yet) and thus there are many other use cases like > e.g. working with RDF-Data, etc. - OK, we don't need to emulate > XMLSerializer then. > > > Also, I don't think it is a good idea to attempt to implement an > > XMLSerializer object for the sake of it, especially when the full > > interface isn't being implemented > > You are right here of course. I was too lazy to look for the > XMLSerializer-interface and see if the other functions can also be simulated > so easy. > > > As a rule I live by the KISS principle, and never optimise code unless > > it becomes a bottleneck, and then only do so under profiling conditions. > > Well, KISS is an optimization strategy :-) Most of the time code is fast > when it is simple, but "most of the time" is not "always". > > Christof > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > -- John Resig http://ejohn.org/ [EMAIL PROTECTED] ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
I'm sorry but I don't agree with this plugin's name or usage. It simply appends multiple valid xml together so the result could be invalid xml and include multiple root elements. In my opinion, the result of any method named .toXML() should be valid xml and the following tests should result in valid XML documents. IE: domDoc.loadXML( $([ item1, item2 ]).toXML() ); FF: (new DOMParser()).parseFromString( $([ item1, item2 ]).toXML(), "text/xml" ); Tony Collins -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christof Donat Sent: Thursday, October 05, 2006 10:02 AM To: jQuery Discussion. Subject: Re: [jQuery] New plugin: toXML (XML serializer) Hi, > The thing is, the main use case for a toXML() call is to send XML data > via an ajax request. Well, I could imagine that there may be other usecases as well, like doing search and replace operations on the string representation of a XML which is reparsed afterwards. It was just a joke, but you may look at that "use case" which could be usefull for XML-Data as well: http://dean.edwards.name/weblog/2006/07/erlaubt/#comment7262 > The duration of the request greatly overshadows any optimisation that > could be applied to toXML. Well, there are also use cases, where you can assume a really fast network connections (inhouse with 1GB-Ethernet e.g.) and thus work with huge datasets on the client side. Then suddenly the time, the client and server need to process the request becomes the dominating factor. I think that jQuery could also be really usefull for Applications using XULrunner (I haven't tried yet) and thus there are many other use cases like e.g. working with RDF-Data, etc. - OK, we don't need to emulate XMLSerializer then. > Also, I don't think it is a good idea to attempt to implement an > XMLSerializer object for the sake of it, especially when the full > interface isn't being implemented You are right here of course. I was too lazy to look for the XMLSerializer-interface and see if the other functions can also be simulated so easy. > As a rule I live by the KISS principle, and never optimise code unless > it becomes a bottleneck, and then only do so under profiling conditions. Well, KISS is an optimization strategy :-) Most of the time code is fast when it is simple, but "most of the time" is not "always". Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
> > As a rule I live by the KISS principle, and never optimise code unless > > it becomes a bottleneck, and then only do so under profiling conditions. > > Well, KISS is an optimization strategy :-) Most of the time code is fast when > it is simple, but "most of the time" is not "always". When writing jQuery plugins I highly don't recommend using for loops instead of each(). Granted it may be, technically, faster to do a loop - but the last time people didn't use .each() (pre-1.0) and when I changed the internal interface, it broken a lot of code. Using .each() is important for keeping the quality of code consistent and working. --John ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Hi, > The thing is, the main use case for a toXML() call is to send > XML data via an ajax request. Well, I could imagine that there may be other usecases as well, like doing search and replace operations on the string representation of a XML which is reparsed afterwards. It was just a joke, but you may look at that "use case" which could be usefull for XML-Data as well: http://dean.edwards.name/weblog/2006/07/erlaubt/#comment7262 > The duration of the request greatly overshadows any optimisation > that could be applied to toXML. Well, there are also use cases, where you can assume a really fast network connections (inhouse with 1GB-Ethernet e.g.) and thus work with huge datasets on the client side. Then suddenly the time, the client and server need to process the request becomes the dominating factor. I think that jQuery could also be really usefull for Applications using XULrunner (I haven't tried yet) and thus there are many other use cases like e.g. working with RDF-Data, etc. - OK, we don't need to emulate XMLSerializer then. > Also, I don't think it is a good idea to attempt to implement an > XMLSerializer object for the sake of it, especially when the full > interface isn't being implemented You are right here of course. I was too lazy to look for the XMLSerializer-interface and see if the other functions can also be simulated so easy. > As a rule I live by the KISS principle, and never optimise code unless > it becomes a bottleneck, and then only do so under profiling conditions. Well, KISS is an optimization strategy :-) Most of the time code is fast when it is simple, but "most of the time" is not "always". Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Christof Donat wrote: > Simulate XMLSerializer globally and use it always - change the serialization > function on first call to distinguish between IE and others. [snip] > I admit, that the two suggestions might not be to easy to understand. I like > to play with functions as values :-) > > At least the first one provides a more general solution by simulating > XMLSerializer and both of them are faster after the first call. That might be > a criterium if you work with large Datasets. If performance is imortant to > you, you might also consider to replace the calls to each() with for-loops. Christof, thanks for your ideas. The thing is, the main use case for a toXML() call is to send XML data via an ajax request. The duration of the request greatly overshadows any optimisation that could be applied to toXML. Also, I don't think it is a good idea to attempt to implement an XMLSerializer object for the sake of it, especially when the full interface isn't being implemented - it could have further reaching effects than you expect. As a rule I live by the KISS principle, and never optimise code unless it becomes a bottleneck, and then only do so under profiling conditions. Regards - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Hi, > I've submitted the XML serializer plugin to the wiki: > > http://jquery.com/docs/Plugins/toXML/ Since Trac doesn't have a possibility to discuss such things before editing the Webpage I'd like to post two other Variants here for discussion: Simulate XMLSerializer globally and use it always - change the serialization function on first call to distinguish between IE and others. if (typeof XMLSerializer == 'function') { XMLSerializer = function() {}; XMLSerializer.prototype.serializeToString = function(node) { var fn = function(node) {return node.xml; }; if (this[0].xml !== undefined) { fn = function(node) { // TODO: Manually serialize DOM here, for browsers // that support neither of two methods above. }; } XMLSerializer.prototype.serializeToString = this.serializeToString = fn return fn(node); } } $.fn.toXML = function () { var out = ''; if (this.length > 0) { var xs = new XMLSerializer(); this.each(function() { out += xs.serializeToString(this); }); } return out; }; Change the toXML-function at first call $.fn.toXML = function () { var fn = function() { var out = ''; this.each(function() { out += this.xml; }); return out; }; if (typeof XMLSerializer == 'function') { fn = function() { var out = ''; var xs = new XMLSerializer(); this.each(function() { out += xs.serializeToString(this); }); return out; }; } else if (this[0].xml === undefined) { fn = function() { var out = ''; // TODO: Manually serialize DOM here, for browsers // that support neither of two methods above. return out; }; } $.fn.toXML = fn; return fn.apply(this,[]); }; I admit, that the two suggestions might not be to easy to understand. I like to play with functions as values :-) At least the first one provides a more general solution by simulating XMLSerializer and both of them are faster after the first call. That might be a criterium if you work with large Datasets. If performance is imortant to you, you might also consider to replace the calls to each() with for-loops. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Oh, that's interesting. Perhaps this page will help you: http://simon-kuehn.de/projekte_innerdom.html (via http://www.strohhalm.org/forum/index.php?action=viewTopic&topic=1516) Mathias 2006/10/5, Mark Gibson <[EMAIL PROTECTED]>: > Hi, > I've submitted the XML serializer plugin to the wiki: > > http://jquery.com/docs/Plugins/toXML/ > > - Mark Gibson > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] New plugin: toXML (XML serializer)
Hi, I've submitted the XML serializer plugin to the wiki: http://jquery.com/docs/Plugins/toXML/ - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/