Check Nothing for attribute getting
Imports System
Imports System.Xml
Imports System.Xml.XPath
Public Class MainClass
Public Shared Sub Main()
Dim root As XElement = <Root Att1="attribute 1 content" Att2="2"/>
Dim att1 As XAttribute = root.Attribute("Att1")
Dim v1 As String
If att1 Is Nothing Then
v1 = Nothing
Else
v1 = att1.Value
End If
Console.WriteLine("v1:{0}", IIf(v1 Is Nothing, "attribute does not exist", v1))
End Sub
End Class
Related examples in the same category