我想扫描我的xml文件,无论特定节点是否存在。然后,我想在消息框中显示文件数。例如,当我浏览乘法文件时,输出将在 MsgBox(( 中显示差异结果
这是我尝试过的:
Private Sub WritingFile(ByVal strContent As String)
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(strContent)
Dim nodes As XmlNode
Try
nodes = xmlDoc.DocumentElement.SelectSingleNode("PRODUCTNAME")
If nodes Is Nothing Then
MsgBox("File Not Exist")<----<--- should display the no. of files not exists
Else
MsgBox("File Exists") <--- should display the no. of files exists
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
如何在没有消息框为每个文件逐个显示的情况下显示结果?谢谢
这是一个如何循环浏览 xml 文件列表的示例
Private fileWithNode As Integer
Private fileWithoutNode As Integer
Private Sub CountValidFiles()
Dim xmlFilePath As String = "c:tempmyxmlfiles"
fileWithNode = 0
fileWithoutNode = 0
For Each filePath As String In Directory.GetFiles(xmlFilePath)
ValidateFile(filePath)
Next
MessageBox.Show(String.Concat(String.Format("Files without node: {0}", fileWithoutNode),
Environment.NewLine,
String.Format("Files with node: {0}", fileWithNode)))
End Sub
Private Sub ValidateFile(strContent As String)
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(strContent)
Dim nodes As XmlNode
Try
nodes = xmlDoc.DocumentElement.SelectSingleNode("PRODUCTNAME")
If nodes Is Nothing Then
fileWithoutNode += 1 ' the no. Of files Not exists
Else
fileWithNode += 1 ' the no. Of files exists
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub