我有一些XML代码必须被打印数百次,但是每行使用不同的值。我想知道是否存在可以使用的在线自动生成器,或者我将不得不创建一个执行该程序的程序。 (对我来说乐观)。
XML:
<INSTANCE>
<ID>1</ID>
<START>0</START>
<END>10</END>
<CODE>00:00:10</CODE>
</INSTANCE>
<INSTANCE>
<ID>2</ID>
<START>10</START>
<END>20</END>
<CODE>00:00:20</CODE>
</INSTANCE>
在ID为1080之前,我一直需要这个。实现此目的的最佳方法是什么?
答案 0 :(得分:0)
//Globals
var ID = 0;
var start =0;
var end =10;
var time = "00:00:00";
var minutes;
var seconds;
var theTime;
var easyReadVar = false;
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var timeCounter=0;
function Go(){
document.getElementById("mainDiv").value += "<file>\n";
document.getElementById("mainDiv").value += "<ALL_INSTANCES>\n";
for (i=1; i <= 1080; i++){
document.getElementById("mainDiv").value += "<instance>\n";
document.getElementById("mainDiv").value += "<ID>" + i + "</ID>\n";
document.getElementById("mainDiv").value += "<start>" + start + "</start>\n";
document.getElementById("mainDiv").value += "<end>" + end + "</end>\n";
timeString();
document.getElementById("mainDiv").value += "<code>" + theTime + "</code>\n";
document.getElementById("mainDiv").value += "</instance>\n";
if (easyReadVar == true){document.getElementById("mainDiv").value += "\n";}
start = start + 10;
end = end + 10;
}
}
function timeString(){
time = end;
if (time < 60){
theTime = "00:00:" + time;
}
else if (time >= 60 && time < 3600){
minutes = time / 60;
minutes = Math.trunc( minutes );
//conditioner - if minutes is single digit, place a zero before
if (minutes <10){minutes = "0" + minutes}
seconds = time - (minutes * 60);
//conditioner - if seconds is single digit, place a zero before
if (seconds <10){seconds = "0" + seconds}
theTime = "00:" + minutes + ":" + seconds;
}
else if (time >= 3600){
hours = (time / 60) / 60;
hours = Math.trunc( hours );
minutes = time - (hours * 60) *60;
minutes = minutes / 60;
minutes = Math.trunc(minutes);
seconds = time - (((hours * 60) * 60) + ((minutes * 60) ));
//conditioner - if hours is single digit, place a zero before
if (hours <10){hours = "0" + hours}
//conditioner - if minutes is single digit, place a zero before
if (minutes <10){minutes = "0" + minutes}
//conditioner - if second is single digit, place a zero before
if (seconds <10){seconds = "0" + seconds}
theTime = hours + ":" + minutes + ":" + seconds;
}
}
function easyRead(){
//The easy reader version - basically flags into main algo to place a return line
resetAllVars();
easyReadVar = true;
document.getElementById("mainDiv").value = "";
Go();
}
function resetAllVars(){
//This is necessary as otherwise variables continue with current values
ID = 0;
start =0;
end =10;
time = "00:00:00";
minutes = 0;
seconds = 0;
theTime = 0;
}
function splash(){
/*Display splash screen on startup (splashDiv)*/
/*THIS SHOULD IDEALLY BE DONE USING JS WINDOW SIZE DETECTION*/
if (timeCounter < 2){
window.document.getElementById("splashDiv").innerHTML = "<img src=\"logo.png\" style=\"width:300px; margin-top: " + (windowHeight /2 - (117/2)) + "px;\">";
window.document.getElementById('wideDiv').style.display = "none";
}
if (timeCounter >= 4){
window.document.getElementById('splashDiv').style.display = "none";
window.document.getElementById('wideDiv').style.display = "block";
}
/*Display for 3 or 2 seconds*/
/*Hide splash screen - similar to menu disappear - display: none;*/
}
function timeTicker(){
setInterval(function(){ splash(); }, 1);
setInterval(function(){ timeCounter; timeCounter++; }, 1000);
}