所以我们最后的XML问题你们马上发现了。所以我还有一个。
以下是我的代码。我想要工作的是,如果XmlReader无法找到它正在搜索的商店编号,则显示一个Msgbox。这可能吗?
Dim store As String = "m" & Storenumber.Text
Dim dir As String = IO.Path.GetTempPath + "\"
Dim xmldocument As String = dir + "IpadCode.xml"
Dim document As XmlReader = New XmlTextReader(xmldocument)
Try
While document.Read()
If (document.Name = store) Then
Output.Text = (document.ReadInnerXml)
End If
End While
Catch
MsgBox("Error pulling store codes")
End Try
修改 我尝试了以下没有运气。它总是说“未找到”
While document.Read()
If (document.Name = store) Then
Output.Text = (document.ReadInnerXml)
Else
MsgBox("Store not found")
Exit Sub
End If
答案 0 :(得分:2)
我假设您的代码正在正确读取XML - 这只是为了向您展示如果document.Name永远=存储,如何处理显示消息的逻辑:
Dim StoreFound as Boolean = False
While document.Read()
If (document.Name = store) Then
Output.Text = (document.ReadInnerXml)
StoreFound = True
End If
End While
If StoreFound = False Then MsgBox("Store not found!")