This documentation is archived and is not being maintained.

XmlValidatingReader.LocalName Property

Gets the local name of the current node.

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

public override string LocalName { get; }

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.

NoteNote:

The XmlValidatingReader class is obsolete in .NET Framework version 2.0. You can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see Validating XML Data with XmlReader.

The following example reads an XML fragment.

using System;
using System.IO;
using System.Xml;

public class Sample
{
    public static void Main()
    {
        XmlTextReader reader = null;

        try
        {
            //Create the XML fragment to be parsed.
            string xmlFrag = "<book> " +
                            "<title>Pride And Prejudice</title>" +
                            "<bk:genre>novel</bk:genre>" +
                            "</book>";

            //Create the XmlNamespaceManager that is used to 
            //look up namespace information.
            NameTable nt = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace("bk", "urn:sample");

            //Create the XmlParserContext.
            XmlParserContext context = new XmlParserContext(null, nsmgr, null, 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())
                {
                    if (reader.Prefix == String.Empty)
                        Console.WriteLine("<{0}>", reader.LocalName);
                    else
                    {
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
                        Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
                    }
                }
            }


        }

        finally
        {
            if (reader != null)
                reader.Close();
        }
    }
} // End class
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlValidatingReader* reader = 0;

   try
   {
      //Create the XML fragment to be parsed.
      String* xmlFrag =S"<book> " 
                       S"<title>Pride And Prejudice</title>" 
                       S"<bk:genre>novel</bk:genre>" 
                       S"</book>"; 

      //Create the XmlNamespaceManager that is used to
      //look up namespace information.
      NameTable* nt = new NameTable();
      XmlNamespaceManager* nsmgr = new XmlNamespaceManager(nt);
      nsmgr->AddNamespace(S"bk", S"urn:sample");

      //Create the XmlParserContext.
      XmlParserContext* context = new XmlParserContext(0, nsmgr, 0, XmlSpace::None);

      //Implement the reader. 
      reader = new XmlValidatingReader(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()){
            if (reader->Prefix==String::Empty)
               Console::WriteLine(S"<{0}>", reader->LocalName);
            else{
               Console::Write(S"<{0}:{1}>", reader->Prefix, reader->LocalName);
               Console::WriteLine(S" The namespace URI is {0}", reader->NamespaceURI);
            }
         }
      }


   } 

   __finally 
   {
      if (reader != 0)
         reader->Close();
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: