0
我喜歡上百個如下例所示的XML,我想在VB.NET中創建一個將這些文件合併爲一個的代碼。將一個文件夾內的XML文件合併到一個XML中
<report>
<Host>10.10.10.4</Host>
<Ping>True</Ping>
<PingResult>True</PingResult>
<start>27/08/2014 14:11:17</start>
<end>27/08/2014 14:11:22</end>
<id>86</id>
<Total>00:00:05</Total>
<success>False</success>
</report>
<report>
<Host>10.10.10.5</Host>
<Ping>True</Ping>
<PingResult>True</PingResult>
<start>27/08/2014 14:11:41</start>
<end>27/08/2014 14:11:58</end>
<id>86</id>
<Total>00:00:17</Total>
<success>False</success>
</report>
功能寫個XML:
Private Sub writeReport(result As Boolean, PingResult As Boolean, IpRangePing As Boolean, iSpan As TimeSpan, StartTime As DateTime, EndTime As DateTime, err As Boolean)
If (Not System.IO.Directory.Exists(Me.FilePath + "\report")) Then
System.IO.Directory.CreateDirectory((Me.FilePath + "\report"))
End If
Dim writer As New XmlTextWriter(Me.FilePath + "\report\" + Me.Id.ToString + Me.HostName + ".xml", Nothing)
writer.WriteStartDocument()
writer.WriteStartElement("report")
writer.WriteElementString("Host", Me.HostName.ToString)
writer.WriteElementString("Ping", IpRangePing.ToString)
writer.WriteElementString("PingResult", PingResult.ToString)
writer.WriteElementString("start", StartTime.ToString)
writer.WriteElementString("end", EndTime.ToString)
writer.WriteElementString("id", Me.Id.ToString)
writer.WriteElementString("Error", err.ToString)
writer.WriteElementString("Total", iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & _
iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & _
iSpan.Seconds.ToString.PadLeft(2, "0"c))
writer.WriteElementString("success", result.ToString)
writer.WriteEndElement()
writer.Close()
End Sub
而我的計劃是利用每個和讀取所有XML,並再創建一個新的。
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me.FilePath + "\report\")
Dim xmlFiles As System.IO.FileInfo() = directory .GetFiles("*.xml")
For Each xmlFile As System.IO.FileInfo In xmlFiles
//To Do
Next
你能列出一些你已經試過的代碼嗎? – Kat 2014-08-27 19:38:33