Mega Code Archive

 
Categories / VB.Net / XML
 

Get attribute and parse to Integer

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 att2 As XAttribute = root.Attribute("Att2")         Dim v2 As Nullable(Of Integer)         If att2 Is Nothing Then             v2 = Nothing         Else             v2 = Int32.Parse(att2.Value)         End If                  Console.WriteLine("v2:{0}", IIf(v2.HasValue, v2, "attribute does not exist"))     End Sub End Class