Return parsed XML based on HTML template
Rely on jquery 1.4
? 1. [Code] The jquery-based XML parser and returns the custom HTML
/**
* jquery Plugin
* Author: [email protected]
* date:2011-02-16
* Params:dom:XMLDocument,
* _default:{
* Reg: Match tag regular,
* LC: Label left Terminator,
* RC: Label right Terminator,
* Script: Whether script is included,
* Scriptid: The node containing the script,
* Tplbox: template,
* Tplhtml: Information entry
* }
* Return:htmldocument
* Note:xml Processing Plugin
*
*/
(function ($) {
$.fn.extend ({
Parsexml:function (dom,option) {
var that=$ (DOM);
var html={};
var tpl= ';
Configuration data
var _default={
Reg:/\{\w+\}/gi,
LC: ' {',
RC: '} ',
Script:true,
Scriptid: ' Script ',
Tplbox: ' <ul class= ' indexiframelist skin3 ' >{item}</ul>{more} ',
tplhtml:{
Item: ' <li><a href= ' {link} ' ><span class= ' timer ' >{pubdate}</span>{title}</a></li > ',
MORE: ' <div class= ' morelink ' ><a href= ' {link} ' >{title}</a></div> ',
Script: ' function {Funcationname}{{funcationcode}} '
} background music http://www.huiyi8.com/bgm/?
}
var option=$.extend (_default,option);
Start processing Tplbody
$.each (Option.tplhtml,function (O,STR) {
var rego=str.match (Option.reg);
Html[o]=[];
$ (o,that). each (function () {
var d=$ (this), shtml=str;
$.each (Rego,function (i,c) {
Shtml=shtml.replace (C,d.find (C.replace (OPTION.LC, "). Replace (option.rc, ')). text ());
});
Html[o].push (shtml);
});
});
Start processing Tplbox
var Tplhtml=option.tplbox;
Tpl=option.tplbox.match (Option.reg);
$.each (Tpl,function (i,c) {
Tplhtml=tplhtml.replace (C,html[c.replace (OPTION.LC, "). Replace (option.rc, ')].join ('));
});
Add a script to a page
if (option.script) {
var script=document.createelement (' script ');
Script.type= "Text/javascript";
Script.text=html[option.scriptid].join (");
$ (' HTML > Head '). Append (script);
}
return tplhtml;
}
});
}) (JQuery);
?
A jquery-based XML parser that returns custom HTML