[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

SelectSingleNode question

Label1.Text = xmlnode.SelectSingleNode("head").SelectSingleNode("title").InnerText

this gives an error when Node doesnt exist. With what "IF"-function can i prevent this error? i think something with .lenth .. but i'm not sure.
Thanks in advanced
0
Amien90
Asked:
Amien90
  • 2
  • 2
1 Solution
 
magicdlfCommented:
Add try catch around the xml reader.
0
 
magicdlfCommented:
0
 
me655321Commented:
you can just do this...

        Dim tmpNode As XmlNode
        tmpNode = xmlnode.SelectSingleNode("head")
        If tmpNode IsNot Nothing Then
            tmpNode = tmpNode.SelectSingleNode("title")
            If tmpNode IsNot Nothing Then
                Label1.Text = tmpNode.InnerText
            End If
        End If
0
 
me655321Commented:
Oh, guess you already got it...sry
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now