Dil

XmlNamedNodeMap.SetNamedItem(XmlNode) Yöntem

Tanım

özelliğini XmlNode kullanarak bir Name ekler.

public:
 virtual System::Xml::XmlNode ^ SetNamedItem(System::Xml::XmlNode ^ node);
public virtual System.Xml.XmlNode SetNamedItem(System.Xml.XmlNode node);
public virtual System.Xml.XmlNode? SetNamedItem(System.Xml.XmlNode? node);
abstract member SetNamedItem : System.Xml.XmlNode -> System.Xml.XmlNode
override this.SetNamedItem : System.Xml.XmlNode -> System.Xml.XmlNode
Public Overridable Function SetNamedItem (node As XmlNode) As XmlNode

Parametreler

node
XmlNode

XmlNode içinde depolamak XmlNamedNodeMapiçin bir. Bu ada sahip bir düğüm haritada zaten varsa, yenisiyle değiştirilir.

Döndürülenler

node mevcut bir düğümü aynı adla değiştirirse, eski düğüm döndürülür; aksi takdirde döndürülürnull.

Özel durumlar

, node öğesini oluşturandan XmlDocumentfarklı XmlNamedNodeMap bir kaynaktan oluşturulmuştur veya XmlNamedNodeMap salt okunurdur.

Örnekler

Aşağıdaki örnek, koleksiyona XmlAttributeCollection bir öznitelik eklemek için sınıfını (öğesinden XmlNamedNodeMapdevralır) kullanır.

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;

     // Add a new attribute to the collection.
     XmlAttribute attr = doc.CreateAttribute("style");
     attr.Value = "hardcover";
     attrColl.SetNamedItem(attr);

     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

    ' Add a new attribute to the collection.
    Dim attr as XmlAttribute = doc.CreateAttribute("style")
    attr.Value = "hardcover"
    attrColl.SetNamedItem(attr)

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

Şunlara uygulanır