語言

XmlNamedNodeMap.GetNamedItem 方法

定義

從 中節點集合XmlNode中取得指定的 XmlNamedNodeMap 。

多載

名稱 Description
GetNamedItem(String)

以名稱檢索指定的資料 XmlNode 。

GetNamedItem(String, String)

取得一個節點,且 與 相匹配LocalNameNamespaceURI。

GetNamedItem(String)

來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs

以名稱檢索指定的資料 XmlNode 。

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

參數

name
String

要取回的節點的限定名稱。 它會與 Name 匹配節點的性質進行匹配。

傳回

若未找到匹配節點,則為指定名稱XmlNode的 Anull。

範例

以下範例使用 XmlAttributeCollection 類別(繼承自 XmlNamedNodeMap)來修改屬性。

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

適用於

GetNamedItem(String, String)

來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs
來源:
XmlNamedNodemap.cs

取得一個節點,且 與 相匹配LocalNameNamespaceURI。

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

參數

localName
String

要擷取節點的本地名稱。

namespaceURI
String

要擷取節點的命名空間統一資源識別碼(URI)。

傳回

XmlNode若找不到匹配的節點,則使用匹配的本地名稱與命名空間 URInull。

適用於