<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Test XML</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <SCRIPT LANGUAGE="JavaScript"> function getParameter(){ aParameter=[1,2,3,4,5,6,7,8]; return aParameter; }
function transXML(aObject){ var aParameter=getParameter(); //create a default xml. var sXml='<parameters>/n'; //if the aObject is not null and empty,set the xml properties by aObject's values. if(aObject&&aObject.length>0){ for(var i=0;i<aParameter.length;i++){ var a=aParameter[i]; sXml+='/t<parameter inuse='+aObject.has(a)+' paramKind='+a+' paramValue=-1 subServiceCode=1></parameter>/n'; } } sXml+='</parameters>'; return sXml; }
function testXML(){ Array.prototype.has=function(obj){ for(var i=0;i<this.length;i++){ var a=this[i]; if(a==obj){ return true; } } return false; }; var p='5#6#8#';//所有的参数都连接到这一个串中 var aP=p.split('#'); var aObject=new Array(); for(var i=0;i<aP.length;i++){ aObject.push(aP[i]); } alert(transXML(aObject)); }