Export (0) Print
Expand All

XmlValidatingReader.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.


The XmlValidatingReader class is obsolete in .NET Framework 2.0. You can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see the Remarks section of the XmlReader reference page.

The following example reads an XML fragment.

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing 

            'Create the XML fragment to be parsed. 
            Dim xmlFrag As String = "<book> " & _
                                    "<title>Pride And Prejudice</title>" & _
                                    "<bk:genre>novel</bk:genre>" & _

            'Create the XmlNamespaceManager that is used to 
            'look up namespace information. 
            Dim nt As New NameTable()
            Dim nsmgr As New XmlNamespaceManager(nt)
            nsmgr.AddNamespace("bk", "urn:sample")

            'Create the XmlParserContext. 
            Dim context As New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)

            'Implement the reader. 
            reader = New XmlTextReader(xmlFrag, XmlNodeType.Element, context)

            'Parse the XML fragment.  If they exist, display the    
            'prefix and namespace URI of each element. 
            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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft