Time Increment In XML

Time Increment In XML

2
NewbieNewbie
2

    Oct 13, 2010#1

    Hello,

    I have a file in XML Format, in that file the date/time value is same in whole file like following example:

    <startdate>2002-05-30T09:30:10Z</startdate>
    <startdate>2002-05-30T09:30:10Z</startdate>
    <startdate>2002-05-30T09:30:10Z</startdate>
    <startdate>2002-05-30T09:30:10Z</startdate>
    <startdate>2002-05-30T09:30:10Z</startdate>
    <startdate>2002-05-30T09:30:10Z</startdate>


    I would like to change that value like this:

    <startdate>2002-05-30T09:30:01Z</startdate>
    <startdate>2002-05-30T09:30:02Z</startdate>
    <startdate>2002-05-30T09:30:03Z</startdate>
    -- -- --- --- --- --- --- --- --- --- ---
    -- -- --- --- --- --- --- --- --- --- ---

    <startdate>2002-05-30T09:30:59Z</startdate>
    <startdate>2002-05-30T09:31:00Z</startdate>
    <startdate>2002-05-30T09:31:01Z</startdate>
    -- -- --- --- --- --- --- --- --- --- ---
    -- -- --- --- --- --- --- --- --- --- ---

    <startdate>2002-05-30Tnn:nn:nnZ</startdate>

    It's not necessary to change the date in case of 23:59:59 + 1 second. I'm using UE v16.10.

    Thanks In Advance....
    ViR

    6,602548
    Grand MasterGrand Master
    6,602548

      Oct 15, 2010#2

      Here is the script for the time increment in your XML file.

      Code: Select all

      if(UltraEdit.document.length > 0) {  // Is any file opened?
      
         // Define working environment for the script.
         UltraEdit.ueReOn();
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         UltraEdit.activeDocument.top();
      
         // Define the parameters needed for the following searches.
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
      
         // Search for the first time string in the file.
         if(UltraEdit.activeDocument.findReplace.find("T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z")) {
      
            // The found string is selected, load it into string variable.
            // Then convert hour, minute and second to integers.
            var sTimeStr = UltraEdit.activeDocument.selection;
            var nHour    = parseInt(sTimeStr.substr(1,2),10);
            var nMinute  = parseInt(sTimeStr.substr(4,2),10);
            var nSecond  = parseInt(sTimeStr.substr(7,2),10);
      
            // Increase all other time strings by 1 second on each
            // occurrence depending on first found time string.
            while(UltraEdit.activeDocument.findReplace.find("T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z")) {
      
               if( ++nSecond >= 60 ) {
                  nSecond = 0;
                  if( ++nMinute >= 60 ) {
                     nMinute = 0;
                     if( ++nHour >= 24 ) nHour = 0;
                  }
               }
               // Build the new time string.
               sTimeStr = 'T';
               if(nHour < 10) sTimeStr += '0';
               sTimeStr += nHour.toString();
               sTimeStr += ':';
               if(nMinute < 10) sTimeStr += '0';
               sTimeStr += nMinute.toString();
               sTimeStr += ':';
               if(nSecond < 10) sTimeStr += '0';
               sTimeStr += nSecond.toString();
               sTimeStr += 'Z';
               // Write the new time string into the file with
               // replacing found time string which is selected.
               UltraEdit.activeDocument.write(sTimeStr);
            }
            UltraEdit.activeDocument.top();
         }
      }
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Oct 15, 2010#3

        Thank You So Much Mofi :) For Giving This Script Your Valuable Time.

        You Made My Day 8)

        Thanks Again !!

        ViR