XmlAttributeCollection.SetNamedItem(XmlNode) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
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
Paraméterek
- node
- XmlNode
A gyűjteményben tárolandó attribútumcsomópont. A csomópont később elérhető lesz a csomópont nevével. Ha egy ilyen nevű csomópont már szerepel a gyűjteményben, azt az új váltja fel; ellenkező esetben a csomópont hozzá lesz fűzve a gyűjtemény végéhez.
Válaszok
Ha a node meglévő csomópontot ugyanazzal a névvel cseréli le, a régi csomópont lesz visszaadva, ellenkező esetben a hozzáadott csomópont lesz visszaadva.
Kivételek
node a gyűjteményt létrehozótól eltérő XmlDocument helyről lett létrehozva.
Ez XmlAttributeCollection írásvédett.
node
XmlAttribute egy olyan objektum, amely már egy másik XmlElement objektum attribútuma. Az attribútumok más elemekben való ismételt használatához klónoznia kell az XmlAttribute újra használni kívánt objektumokat.
Példák
Az alábbi példa egy új attribútumot ad hozzá egy dokumentumhoz.
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