- rem 另存为 ANSI 编码 的 bat
- ' & cls & %windir%\SysWOW64\CScript.exe /nologo /e:vbscript "%~f0" & pause & exit
-
- Option Explicit
- Dim oWshShell, oFSO, oTextStream, oDOMDocument, oXMLDOMElement, oConnection, oRecordset, s, t
-
- Const PATH = "C:\Users\Administrator\Desktop\items"
- Const OUT = "C:\Users\Administrator\Desktop\items\输出.txt"
-
- wsh.Echo Now()
- Set oWshShell = CreateObject("WScript.Shell")
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oTextStream = oFSO.OpenTextFile(OUT, 2, True)
- Set oDOMDocument = CreateObject("Msxml2.DOMDocument")
- Set oConnection = CreateObject("ADODB.Connection")
- Set oRecordset = CreateObject("ADODB.Recordset")
-
- s = oFSO.BuildPath(PATH, "temp.mdb")
- If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
- s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & s
- CreateObject("ADOX.Catalog").Create s
- oConnection.Open s
- oConnection.Execute "CREATE TABLE list(id INT PRIMARY KEY, name VARCHAR)"
-
- t = "|"
- For Each s In oFSO.GetFolder(PATH).Files
- If LCase(oFSO.GetExtensionName(s)) = "xml" Then Call k(s.Path)
- Next
-
- oRecordset.CursorLocation = 3 'adUseClient
- oRecordset.Open "SELECT * FROM list ORDER BY id ASC", oConnection
- s = ""
- For t = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(t).Name & vbTab
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- Do Until oRecordset.EOF = True
- For t = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(t).Value & vbTab
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- If Len(s) >= 2048 Then
- oTextStream.Write s
- s = ""
- End If
- oRecordset.MoveNext()
- Loop
- If s <> "" Then oTextStream.Write s
- oRecordset.Close()
- oConnection.Close()
- oTextStream.Close()
-
- s = oFSO.BuildPath(PATH, "temp.mdb")
- If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
- wsh.Echo Now()
- wsh.Echo "ok"
-
- Sub k(ByVal s)
- Dim i, j, m
- oDOMDocument.Load s
- Set oXMLDOMElement = oDOMDocument.documentElement
- For Each i In oXMLDOMElement.SelectNodes("item[@id and @name]")
- oConnection.Execute "INSERT INTO list(id, name) VALUES(" & i.getAttribute("id") & ", '" & i.getAttribute("name") & "')"
- m = "UPDATE list SET "
- For Each j In i.SelectNodes(".//*[@val]")
- If Not IsNull(j.getAttribute("name")) Then
- If InStr(1, t, "|" & j.getAttribute("name") & "|", vbTextCompare) = 0 Then
- oConnection.Execute "ALTER TABLE list ADD COLUMN [" & j.getAttribute("name") & "] VARCHAR"
- t = t & j.getAttribute("name") & "|"
- End If
- If InStr(1, m, "[" & j.getAttribute("name") & "]", vbTextCompare) = 0 Then '处理异常文件 id = 20994
- m = m & "[" & j.getAttribute("name") & "] = """ & j.getAttribute("val") & """, "
- End If
- End If
- If Not IsNull(j.getAttribute("stat")) Then
- If InStr(1, t, "|" & j.getAttribute("stat") & "|", vbTextCompare) = 0 Then
- oConnection.Execute "ALTER TABLE list ADD COLUMN [" & j.getAttribute("stat") & "] VARCHAR"
- t = t & j.getAttribute("stat") & "|"
- End If
- If InStr(1, m, "[" & j.getAttribute("stat") & "]", vbTextCompare) = 0 Then
- m = m & "[" & j.getAttribute("stat") & "] = """ & j.getAttribute("val") & """, "
- End If
- End If
- Next
- oConnection.Execute Left(m, Len(m) - 2) & " WHERE id = " & i.getAttribute("id")
- Next
- End Sub
复制代码
|