Hello All...I need some help with a VBSCRIPT. I have 100's of XML files and I need the vbscript to search for a tag and update partial contents within the tag. Example below:
<address>1 Main St</address>
<startDateTime>2011-01-06-13:00:00</startDateTime>
<endDateTime>2011-01-06-17:00:00</endDateTime>
I want the program to go through the XML file and replace the date between the tag with a variable date (dtDate - which represents current date), while leaving the time alone. So it would change 2011-01-06 to 2011-01-07. When I run the VBScript, the values in the tags will differ so I cannot run the search / replace command. That is why I think just using the start tag of <startDateTime> should be what the program uses to find the starting point.
I have the starting of the script below - any help would be a huge help and greatly appreciated!!
Const ForReading = 1
Const ForWriting = 2
strYr = Year(date)
strMth = Month(date)
strDay = Day(date)
if len(strYr) < 4 then
strYr = "20" & Year(date)
end if
if len(strMth) < 2 then
strMth = "0" & Month(date)
end if
if len(strDay) < 2 then
strDay = "0" & Day(date)
end if
dtDateE = strYr & "-" & strMth & "-" & strDay
msgbox dtDateE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\Test\a.xml", ForReading)
strText = objFile.ReadAll
objFile.Close
' HERE IS WHERE THE CODE SHOULD GO
Set objFile = objFSO.OpenTextFile("C:\temp\test\a.xml", ForWriting)
objFile.WriteLine strNewText
objFile.Close
<address>1 Main St</address>
<startDateTime>2011-01-06-13:00:00</startDateTime>
<endDateTime>2011-01-06-17:00:00</endDateTime>
I want the program to go through the XML file and replace the date between the tag with a variable date (dtDate - which represents current date), while leaving the time alone. So it would change 2011-01-06 to 2011-01-07. When I run the VBScript, the values in the tags will differ so I cannot run the search / replace command. That is why I think just using the start tag of <startDateTime> should be what the program uses to find the starting point.
I have the starting of the script below - any help would be a huge help and greatly appreciated!!
Const ForReading = 1
Const ForWriting = 2
strYr = Year(date)
strMth = Month(date)
strDay = Day(date)
if len(strYr) < 4 then
strYr = "20" & Year(date)
end if
if len(strMth) < 2 then
strMth = "0" & Month(date)
end if
if len(strDay) < 2 then
strDay = "0" & Day(date)
end if
dtDateE = strYr & "-" & strMth & "-" & strDay
msgbox dtDateE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\Test\a.xml", ForReading)
strText = objFile.ReadAll
objFile.Close
' HERE IS WHERE THE CODE SHOULD GO
Set objFile = objFSO.OpenTextFile("C:\temp\test\a.xml", ForWriting)
objFile.WriteLine strNewText
objFile.Close