XmlTextReader,如果找不到文本

XmlTextReader, if text not found

所以我的最后一个 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

编辑 我尝试了以下但没有运气。它总是说 "Not found"

While document.Read()
            If (document.Name = store) Then
                Output.Text = (document.ReadInnerXml)
            Else
                MsgBox("Store not found")
                Exit Sub
            End If

我假设您的代码正在正确读取 XML——这只是为了向您展示如果 document.Name 永远不会 = store:

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!")