This documentation is archived and is not being maintained.

XmlNamedNodeMap.GetNamedItem Method (String)

Retrieves an XmlNode specified by name.

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

public virtual XmlNode GetNamedItem(
	string name
)

Parameters

name
Type: System.String
The qualified name of the node to retrieve. It is matched against the Name property of the matching node.

Return Value

Type: System.Xml.XmlNode
An XmlNode with the specified name or null if a matching node is not found.

The following example uses the XmlAttributeCollection class (which inherits from XmlNamedNodeMap) to modify an attribute.


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

public class Sample
{
  public static void Main()
  {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml("<book genre='novel' publicationdate='1997'> " +
                 "  <title>Pride And Prejudice</title>" +
                 "</book>");      

     XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

     // Change the value for the genre attribute.
     XmlAttribute attr = (XmlAttribute)attrColl.GetNamedItem("genre");
     attr.Value = "fiction";

     Console.WriteLine("Display the modified XML...");
     Console.WriteLine(doc.OuterXml);

  }
}


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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