如何转换使用已弃用的E4X的脚本?

Flickr Functional Suite

我不是程序员,但是如果您向我解释我需要从哪里开始,我会尽力而为。

首先,似乎不是CDATA的问题...

这是Buggzilla中的链接,我在其中描述我的问题:
Firefox 17 breaks a Greasemonkey script that relies on E4X (New : Firefox 21 delete totally its support)

我在这里获得使用E4x的第一张索引(在代码“ ricCB”中搜索):

requestImageComments: function( id ) {
    if (!id) return;
    var tkey = 'getComments';
    // Set up ticket status queue if needed
    if (!this.ticketStatus[tkey]) this.ticketStatus[tkey] = new Object();
    return this.flickrApi
    ( { method: 'flickr.photos.comments.getList', photo_id: id },
      'ricCB', {ticktype: tkey} );
},
ricCB: function(rsp) {
    var hash = this.objects.comments;
    for each (comments in rsp.comments) {
        // for (var cs = 0; cs < rsp.comments.length; cs++) {
        // var comments = rsp.comments[cs];
        var pid  = comments.@photo_id;
        for each (com in comments.comment) {
            var uname  = com.@authorname;
            var nsid   = com.@author;
            this.setTranslation( { uname: uname, nsid: nsid } );
            // var create = new Date( com.@datecreate );
            var ctxt  = com + '';
            // Strip out HTML tags:
            ctxt = ctxt.replace(/(\<|\&lt\;).+?(\>|\&gt\;)/g,'');
            // Collapse all whitespace runs to single spaces:
            ctxt = ctxt.replace(/[\s\n\r\t]+/g, ' ');
            // Store data under both authorname and photo ID (hash
            // will collide only if someone is using a pure
            // integer as a name AND a photo has same integer).
            var info = { txt: ctxt, uname: uname, photo: pid };
            if (!hash[uname]) hash[uname] = new Array();
            if (!hash[pid])   hash[pid]   = new Array();
            hash[uname].push(info);
            hash[pid].push(info);
        }
    }


最初发布在这里:
My Greasemonkey script stopped working after something updated

最佳答案

如果对e4x有依赖性,请尝试包括JavaScript实现:


e4x.js


作为替代,这里还有其他问题,涉及将e4x语法映射到XPath或将XML映射到JSON:


What is the Flex/AS3/E4X equivalent of this xpath query?
Howto convert E4X XML Elements into JSON Notation


此外,您可以通过yql访问数据来继续使用e4x:


Using e4x with yql


参考文献


AJAX and scripting web services with E4X, Part 1
E4X Missing in JS - Apache Flex - Apache Software Foundation
E4X Observations - Apache Flex - Apache Software Foundation

10-07 23:45