XmlAttributeCollection.SetNamedItem(XmlNode) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
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
매개 변수
- node
- XmlNode
이 컬렉션에 저장할 Attribute 노드입니다. 노드 이름을 사용하여 나중에 노드에 액세스할 수 있습니다. 컬렉션에 해당 이름의 노드가 이미 있으면 새 노드로 바뀌고, 그렇지 않으면 노드가 컬렉션 끝에 추가됩니다.
반환
node가 기존 노드를 같은 이름으로 바꾸면 이전 노드가 반환되고, 그렇지 않으면 추가된 노드가 반환됩니다.
예외
node가 이미 다른 XmlAttribute 개체의 특성인 XmlElement인 경우. 다른 요소에서 특성을 다시 사용하려면 다시 사용할 XmlAttribute 개체를 복제해야 합니다.
예제
다음은 문서에 새 특성을 추가하는 예제입니다.
#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