XmlNamedNodeMap.GetNamedItem 方法

定義

XmlNode 的節點集合中擷取指定的 XmlNamedNodeMap

多載

GetNamedItem(String)

依指定名稱來擷取 XmlNode

GetNamedItem(String, String)

擷取具有符合的 LocalNameNamespaceURI 的節點。

GetNamedItem(String)

Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs
Source:
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

要擷取的節點的限定名稱 (Qualified Name)。 它會與符合節點的 Name 屬性比對。

傳回

具有指定名稱的 XmlNode;如果找不到符合的節點,則為 null

範例

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

#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

適用於

GetNamedItem(String, String)

Source:
XmlNamedNodemap.cs
Source:
XmlNamedNodemap.cs
Source:
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)。

傳回

具有符合的區域名稱與命名空間 (Namespace) URI 的 XmlNode;如果找不到符合的節點,則為 null

適用於