XmlNamedNodeMap.GetNamedItem Método

Definición

Recupera el objeto XmlNode especificado de la colección de nodos de XmlNamedNodeMap.

Sobrecargas

GetNamedItem(String)

Recupera un objeto XmlNode especificado por el nombre.

GetNamedItem(String, String)

Recupera un nodo con LocalName y NamespaceURI coincidentes.

GetNamedItem(String)

Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs

Recupera un objeto XmlNode especificado por el nombre.

public:
 virtual System::Xml::XmlNode ^ GetNamedItem(System::String ^ name);
public virtual System.Xml.XmlNode GetNamedItem (string name);
public virtual System.Xml.XmlNode? GetNamedItem (string name);
abstract member GetNamedItem : string -> System.Xml.XmlNode
override this.GetNamedItem : string -> System.Xml.XmlNode
Public Overridable Function GetNamedItem (name As String) As XmlNode

Parámetros

name
String

Nombre completo del nodo que se va a recuperar. Se compara con la propiedad Name del nodo coincidente.

Devoluciones

XmlNode con el nombre especificado o null si no se encuentra ningún nodo coincidente.

Ejemplos

En el ejemplo siguiente se usa la XmlAttributeCollection clase (que hereda de XmlNamedNodeMap) para modificar un atributo.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 = dynamic_cast<XmlAttribute^>(attrColl->GetNamedItem( "genre" ));
   attr->Value = "fiction";
   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->OuterXml );
}
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);
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book genre='novel' publicationdate='1997'> " & _
                "  <title>Pride And Prejudice</title>" & _
                "</book>")
                         
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes

    ' Change the value for the genre attribute.
    Dim attr as XmlAttribute = CType(attrColl.GetNamedItem("genre"),XmlAttribute)
    attr.Value = "fiction"

    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.OuterXml)
    
  end sub
end class

Se aplica a

GetNamedItem(String, String)

Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs

Recupera un nodo con LocalName y NamespaceURI coincidentes.

public:
 virtual System::Xml::XmlNode ^ GetNamedItem(System::String ^ localName, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode GetNamedItem (string localName, string namespaceURI);
public virtual System.Xml.XmlNode? GetNamedItem (string localName, string? namespaceURI);
abstract member GetNamedItem : string * string -> System.Xml.XmlNode
override this.GetNamedItem : string * string -> System.Xml.XmlNode
Public Overridable Function GetNamedItem (localName As String, namespaceURI As String) As XmlNode

Parámetros

localName
String

Nombre local del nodo que se va a recuperar.

namespaceURI
String

El Identificador uniforme de recursos (Identificador URI) del espacio de nombres del nodo a recuperar.

Devoluciones

XmlNode con el nombre local y el identificador URI de espacio de nombres coincidentes o null si no se ha encontrado un nodo coincidente.

Se aplica a