On Jun 28, 2006, at 9:41 PM, Damjan wrote:

>
>> It does have some nice features. I'd like to see all the CSS-selector
>> emulation in MochiKit, but adding properties to or proxying DOM
>> objects is not something I want MochiKit to do.
>
> Yes, that's the single greatest feature of jQuery, the CSS and Xpath
> selector. And it can work on any document. Consider this very easy rss
> reader:
>
> $.get("rss20.xml", got_response);
> function got_response(xml) {
>     var items = $("/rss/channel/item", xml);
>     items.each( function() {
>         var title = $('title', this).get(0).firstChild.nodeValue;
>         var link = $('link', this).get(0).childNodes[0].nodeValue;
>         $('ul#rss_titles').append( $.LI({}, $.A({href:link},  
> title)) );
>     });
> };
>
> BTW How would I do this with Mochikit?

It wouldn't be terribly concise. without the CSS/XPath support.

var req = getXMLHttpRequest();
if (req.overrideMimeType) req.overrideMimeType("text/xml");
req.open("GET", url, true);
var d = sendXMLHttpRequest(req);
d.addCallback(function (req) {
     var rssElements =  
req.responseXML.documentElement.getElementsByTagName("rss");
     var rss_titles = getElementsByTagAndClassName("ul", "rss_titles") 
[0];
     forEach(rssElements, function (rss) {
        var channelElements = rss.getElementsByTagName("channel");
        forEach(channelElements, function (channel) {
             var items = channel.getElementsByTagName("item");
             forEach(items, function (item) {
                 var title = scrapeText(item.getElementsByTagName 
("title")[0]);
                 var link = scrapeText(item.getElementsByTagName 
("link")[0]);
                 appendChildNodes(rss_titles, LI(null, A({href:  
link}, title)));
             });
         });
     });
});

Clearly, MochiKit is not currently optimized for finding DOM nodes by  
anything more complicated by id.

-bob


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to