XmlNamedNodeMap.SetNamedItem(XmlNode) 메서드

정의

해당하는 XmlNode 속성을 사용하여 Name를 추가합니다.Adds an XmlNode using its Name property.

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

매개 변수

node
XmlNode

XmlNode에 저장할 XmlNamedNodeMap입니다.An XmlNode to store in the XmlNamedNodeMap. 해당하는 이름의 노드가 이미 맵에 있을 경우에는 새 노드로 대체됩니다.If a node with that name is already present in the map, it is replaced by the new one.

반환

node에서 같은 이름을 가진 기존 노드를 대체할 경우 이전 노드가 반환되고, 그렇지 않으면 null이 반환됩니다.If the node replaces an existing node with the same name, the old node is returned; otherwise, null is returned.

예외

XmlNamedNodeMap을 만든 문서가 아니라 다른 XmlDocument에서 node를 만들었거나 XmlNamedNodeMap이 읽기 전용인 경우The node was created from a different XmlDocument than the one that created the XmlNamedNodeMap; or the XmlNamedNodeMap is read-only.

예제

다음 예제에서는 XmlNamedNodeMap에서 상속 되는 XmlAttributeCollection 클래스를 사용 하 여 컬렉션에 특성을 추가 합니다.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

적용 대상