例如,源文件包含(请注意多条<?xml
行):
08/29/2018
08:47:21
<?xml version="1.0" encoding="utf-8"?><ExtendedData><Header><Date>08/29/18</Date>.. other data</ExtendedData>
08/29/2018
08:50:53
<?xml version="1.0" encoding="utf-8"?><ExtendedData><Header><Date>08/29/18</Date>.. other data</ExtendedData>
需要使用VBScript查询xml,我们没有PowerShell的选项(我知道会更好)。
我使用了以下TechNet文章来开始我正在使用的脚本的基础: https://technet.microsoft.com/en-us/library/2008.10.heyscriptingguy.aspx
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FL,oFSO,objFolder,colFiles,objFile,FLPath,FLName,f1,line,xmlDoc,colNodes,objNode,strDate
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = oFSO.GetFolder("H:\Documents\Journal_Files")
Set colFiles = objFolder.Files
For Each objFile In colFiles
FLPath = objFile.Path
FLName = objFile.Name
If InStr(FLName, ".jrn") > 0 Then
'WScript.Echo FLPath
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load(FLPath)
Set colNodes=xmlDoc.selectNodes ("//ExtendedData/Header/Date")
For Each objNode in colNodes
Wscript.Echo objNode.Text
Next
end if
next
问题在于日期没有返回任何内容。