Как я могу автоматически увеличивать числа в коде XML? - PullRequest
0 голосов
/ 18 декабря 2018

У меня есть некоторый код 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>

Мне нужно это до идентификатора 1080. Каков наилучший метод для достижения этой цели?

1 Ответ

0 голосов
/ 19 декабря 2018
//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);   
}
...