📄 atomparser.as
字号:
/**
* Parses ATOM feeds and returns an indexed array with all elements
*
* @author Jeroen Wijering
* @version 1.0
**/
import com.jeroenwijering.feeds.AbstractParser;
import com.jeroenwijering.utils.StringMagic;
class com.jeroenwijering.feeds.ATOMParser extends AbstractParser {
/** Contructor **/
function ATOMParser(enc:Boolean,pre:String) { super(enc,pre); };
/** build an array with all regular elements **/
private function setElements() {
elements = new Object();
elements["title"] = "title";
elements["id"] = "id";
};
/** Convert ATOM structure to array **/
private function parse(xml:XML):Array {
var arr = new Array();
var tpl = xml.firstChild.firstChild;
while(tpl != null) {
if (tpl.nodeName.toLowerCase() == "entry") {
var obj = new Object();
for(var j=0; j<tpl.childNodes.length; j++) {
var nod:XMLNode = tpl.childNodes[j];
if(elements[nod.nodeName] != undefined) {
obj[elements[nod.nodeName]]=nod.firstChild.nodeValue;
} else if(nod.nodeName == "link" &&
nod.attributes.rel == "alternate") {
obj["link"] = nod.attributes.href;
} else if(nod.nodeName == "summary") {
obj["description"] = StringMagic.stripTagsBreaks(
nod.firstChild.nodeValue);
} else if(nod.nodeName == "published") {
obj["date"] = iso2Date(nod.firstChild.nodeValue);
} else if(nod.nodeName == "updated") {
obj["date"] = iso2Date(nod.firstChild.nodeValue);
} else if(nod.nodeName == "modified") {
obj["date"] = iso2Date(nod.firstChild.nodeValue);
} else if(nod.nodeName == "category") {
obj["category"] = nod.attributes.term;
} else if(nod.nodeName == "author") {
for(var k=0; k< nod.childNodes.length; k++) {
if(nod.childNodes[k].nodeName == "name") {
obj["author"] =
nod.childNodes[k].firstChild.nodeValue;
}
}
} else if(nod.nodeName == "link" &&
nod.attributes.rel == "enclosure") {
if(mimetypes[nod.attributes.type.toLowerCase()]
!= undefined) {
obj["file"] = prefix + nod.attributes.href;
obj["type"] = mimetypes[
nod.attributes.type.toLowerCase()];
if(obj["file"].substr(0,4) == "rtmp") {
obj["type"] == "rtmp";
}
}
} else if(nod.nodeName == "link" &&
nod.attributes.rel == "captions") {
obj["captions"] = nod.attributes.href;
} else if(nod.nodeName == "link" &&
nod.attributes.rel == "image") {
obj["image"] = nod.attributes.href;
}
}
obj["author"] == undefined ? obj["author"] = ttl: null;
if(obj["type"] != undefined || enclosures == false) {
arr.push(obj);
}
} else if (tpl.nodeName == "title") {
var ttl = tpl.firstChild.nodeValue;
}
tpl = tpl.nextSibling;
}
return arr;
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -