XmlAttributeCollection.SetNamedItem(XmlNode) 메서드

정의

XmlNode using 속성을 추가합니다Name.

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

매개 변수

node
XmlNode

이 컬렉션에 저장할 특성 노드입니다. 노드는 나중에 노드의 이름을 사용하여 액세스할 수 있습니다. 해당 이름의 노드가 컬렉션에 이미 있는 경우 새 노드로 대체됩니다. 그렇지 않으면 노드가 컬렉션의 끝에 추가됩니다.

반품

node 기존 노드를 동일한 이름으로 바꾸면 이전 노드가 반환되고, 그렇지 않으면 추가된 노드가 반환됩니다.

예외

node 은 이 컬렉션을 만든 컬렉션과 다른 XmlDocument 형식으로 만들어졌습니다.

읽기 XmlAttributeCollection 전용입니다.

nodeXmlAttribute 이미 다른 XmlElement 개체의 특성입니다. 다른 요소의 특성을 다시 사용하려면 다시 사용하려는 개체를 XmlAttribute 복제해야 합니다.

예제

다음은 문서에 새 특성을 추가하는 예제입니다.

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

적용 대상