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
Amien90Asked:
Who is Participating?
 
magicdlfCommented:
0
 
magicdlfCommented:
Add try catch around the xml reader.
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.