XmlAttributeCollection.SetNamedItem(XmlNode) Yöntem

Tanım

özelliğini kullanarak Name bir XmlNode ekler.

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

Parametreler

node
XmlNode

Bu koleksiyonda depolamak için bir öznitelik düğümü. Düğüme daha sonra düğümün adı kullanılarak erişilebilir. Koleksiyonda bu ada sahip bir düğüm zaten varsa, yenisiyle değiştirilir; aksi takdirde düğüm, koleksiyonun sonuna eklenir.

Döndürülenler

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

Özel durumlar

node , bu koleksiyonu oluşturandan farklı XmlDocument bir kaynaktan oluşturulmuştur.

Bu XmlAttributeCollection salt okunurdur.

nodeXmlAttribute, zaten başka XmlElement bir nesnenin özniteliği olan bir nesnedir. Öznitelikleri diğer öğelerde yeniden kullanmak için, yeniden kullanmak istediğiniz nesneleri kopyalamanız XmlAttribute gerekir.

Örnekler

Aşağıdaki örnek belgeye yeni bir öznitelik ekler.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   
   //Create a new attribute.
   XmlAttribute^ newAttr = doc->CreateAttribute( "genre" );
   newAttr->Value = "novel";
   
   //Create an attribute collection and add the new attribute
   //to the collection.
   XmlAttributeCollection^ attrColl = doc->DocumentElement->Attributes;
   attrColl->SetNamedItem( newAttr );
   Console::WriteLine( "Display the modified XML...\r\n" );
   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 ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create a new attribute.
    XmlAttribute newAttr = doc.CreateAttribute("genre");
    newAttr.Value = "novel";

    //Create an attribute collection and add the new attribute
    //to the collection.
    XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
    attrColl.SetNamedItem(newAttr);

    Console.WriteLine("Display the modified XML...\r\n");
    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 ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")      

    'Create a new attribute.
    Dim newAttr as XmlAttribute = doc.CreateAttribute("genre")
    newAttr.Value = "novel"

    'Create an attribute collection and add the new attribute
    'to the collection.  
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
    attrColl.SetNamedItem(newAttr)

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

  end sub
end class

Şunlara uygulanır