Export (0) Print
Expand All

XmlNodeReader.LocalName Property

Gets the local name of the current node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Public Overrides ReadOnly Property LocalName As String

Property Value

Type: System.String
The name of the current node with the prefix removed. For example, LocalName is book for the element <bk:book>.
For node types that do not have a name (like Text, Comment, and so on), this property returns String.Empty.


In the .NET Framework 2.0, the recommended practice is to create XmlReader instances using the XmlReaderSettings class and the Create method. This allows you to take full advantage of all the new features introduced in the .NET Framework. For more information, see the Remarks section in the XmlReader reference page.

The following example displays the local name of each node, and, if they exist, the prefix and namespace URI.

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing 

            'Create and load the XML document. 
            Dim doc As New XmlDocument()
            doc.LoadXml("<book xmlns:bk='urn:samples'> " & _
                       "<title>Pride And Prejudice</title>" & _
                       "<bk:genre>novel</bk:genre>" & _

            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)

            'Parse the XML.  If they exist, display the prefix and   
            'namespace URI of each node. 
            While reader.Read()
                If reader.IsStartElement() Then 
                    If reader.Prefix = String.Empty Then
                        Console.WriteLine("<{0}>", reader.LocalName)
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
                        Console.WriteLine(" The namespace URI is " & reader.NamespaceURI)
                    End If 
                End If 
            End While 

            If Not (reader Is Nothing) Then
            End If 
        End Try 
    End Sub 'Main 
End Class 'Sample 

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft