XmlNamedNodeMap.SetNamedItem(XmlNode) Método
Definição
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
Parâmetros
- node
- XmlNode
Um XmlNode a ser armazenado no XmlNamedNodeMap.An XmlNode to store in the XmlNamedNodeMap. Se um nó com esse nome já existir no mapa, ele será substituído pelo novo.If a node with that name is already present in the map, it is replaced by the new one.
Retornos
Se o node substituir um nó existente com o mesmo nome, o nó antigo será retornado; caso contrário, null será retornado.If the node replaces an existing node with the same name, the old node is returned; otherwise, null is returned.
Exceções
O node foi criado com base em um XmlDocument diferente daquele que criou o XmlNamedNodeMap ou o XmlNamedNodeMap é somente leitura.The node was created from a different XmlDocument than the one that created the XmlNamedNodeMap; or the XmlNamedNodeMap is read-only.
Exemplos
O exemplo a seguir usa a XmlAttributeCollection classe (que herda de XmlNamedNodeMap ) para adicionar um atributo à coleção.The following example uses the XmlAttributeCollection class (which inherits from XmlNamedNodeMap) to add an attribute to the collection.
#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;
// 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 );
}
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