diff -r a908b05787d1 -r 60453502674e org.symbian.tools.wrttools.previewer/preview/script/xml2json.js --- a/org.symbian.tools.wrttools.previewer/preview/script/xml2json.js Fri Apr 09 11:42:56 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* -xml2json v 1.1 -copyright 2005-2007 Thomas Frank - -This program is free software under the terms of the -GNU General Public License version 2 as published by the Free -Software Foundation. It is distributed without any warranty. -*/ - -var xml2json={ - parser:function(xmlcode,ignoretags,debug){ - if(!ignoretags){ignoretags=""}; - xmlcode=xmlcode.replace(/\s*\/>/g,'/>'); - xmlcode=xmlcode.replace(/<\?[^>]*>/g,"").replace(/<\![^>]*>/g,""); - if (!ignoretags.sort){ignoretags=ignoretags.split(",")}; - var x=this.no_fast_endings(xmlcode); - x=this.attris_to_tags(x); - x=escape(x); - x=x.split("%3C").join("<").split("%3E").join(">").split("%3D").join("=").split("%22").join("\""); - for (var i=0;i","g"),"*$**"+ignoretags[i]+"**$*"); - x=x.replace(new RegExp("","g"),"*$***"+ignoretags[i]+"**$*") - }; - x=''+x+''; - this.xmlobject={}; - var y=this.xml_to_object(x).jsontagwrapper; - if(debug){y=this.show_json_structure(y,debug)}; - return y - }, - xml_to_object:function(xmlcode){ - var x=xmlcode.replace(/<\//g,"�"); - x=x.split("<"); - var y=[]; - var level=0; - var opentags=[]; - for (var i=1;i")[0]; - opentags.push(tagname); - level++ - y.push(level+"<"+x[i].split("�")[0]); - while(x[i].indexOf("�"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()} - }; - var oldniva=-1; - var objname="this.xmlobject"; - for (var i=0;i")[0]; - tagnamn=tagnamn.toLowerCase(); - var rest=y[i].split(">")[1]; - if(niva<=oldniva){ - var tabort=oldniva-niva+1; - for (var j=0;j") - } - } - else {rest="{}"}; - if(rest.charAt(0)=="'"){rest='unescape('+rest+')'}; - if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"}; - var before="=";after=""; - if (already){before=".push(";after=")"}; - var toeval=preeval+objname+before+rest+after; - eval(toeval); - if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"}; - oldniva=niva - }; - return this.xmlobject - }, - show_json_structure:function(obj,debug,l){ - var x=''; - if (obj.sort){x+="[\n"} else {x+="{\n"}; - for (var i in obj){ - if (!obj.sort){x+=i+":"}; - if (typeof obj[i] == "object"){ - x+=this.show_json_structure(obj[i],false,1) - } - else { - if(typeof obj[i]=="function"){ - var v=obj[i]+""; - //v=v.replace(/\t/g,""); - x+=v - } - else if(typeof obj[i]!="string"){x+=obj[i]+",\n"} - else {x+="'"+obj[i].replace(/\'/g,"\\'").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")+"',\n"} - } - }; - if (obj.sort){x+="],\n"} else {x+="},\n"}; - if (!l){ - x=x.substring(0,x.lastIndexOf(",")); - x=x.replace(new RegExp(",\n}","g"),"\n}"); - x=x.replace(new RegExp(",\n]","g"),"\n]"); - var y=x.split("\n");x=""; - var lvl=0; - for (var i=0;i=0 || y[i].indexOf("]")>=0){lvl--}; - tabs="";for(var j=0;j=0 || y[i].indexOf("[")>=0){lvl++} - }; - if(debug=="html"){ - x=x.replace(//g,">"); - x=x.replace(/\n/g,"
").replace(/\t/g,"    ") - }; - if (debug=="compact"){x=x.replace(/\n/g,"").replace(/\t/g,"")} - }; - return x - }, - no_fast_endings:function(x){ - x=x.split("/>"); - for (var i=1;i"+x[i] - } ; - x=x.join(""); - return x - }, - attris_to_tags: function(x){ - var d=' ="\''.split(""); - x=x.split(">"); - for (var i=0;i"); - x=x.replace(/ ([^=]*)=([^ |>]*)/g,"><$1>$2"/g,">").replace(/"