XmlElement.SetAttributeNode 메서드

정의

XmlAttribute를 추가합니다.

오버로드

SetAttributeNode(XmlAttribute)

지정된 XmlAttribute를 추가합니다.

SetAttributeNode(String, String)

지정된 XmlAttribute를 추가합니다.

SetAttributeNode(XmlAttribute)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

지정된 XmlAttribute를 추가합니다.

public:
 virtual System::Xml::XmlAttribute ^ SetAttributeNode(System::Xml::XmlAttribute ^ newAttr);
public virtual System.Xml.XmlAttribute SetAttributeNode (System.Xml.XmlAttribute newAttr);
public virtual System.Xml.XmlAttribute? SetAttributeNode (System.Xml.XmlAttribute newAttr);
abstract member SetAttributeNode : System.Xml.XmlAttribute -> System.Xml.XmlAttribute
override this.SetAttributeNode : System.Xml.XmlAttribute -> System.Xml.XmlAttribute
Public Overridable Function SetAttributeNode (newAttr As XmlAttribute) As XmlAttribute

매개 변수

newAttr
XmlAttribute

이 요소의 특성 컬렉션에 추가할 XmlAttribute 노드입니다.

반환

특성이 같은 이름을 가진 기존 특성을 대체할 경우 이전 XmlAttribute가 반환됩니다. 그렇지 않으면 null이 반환됩니다.

예외

이 노드를 만든 문서가 아닌 다른 문서에서 newAttr를 만든 경우 이 노드가 읽기 전용인 경우

newAttr가 이미 다른 XmlElement 개체의 특성인 경우. 다른 XmlAttribute 개체에서 다시 사용하려면 명시적으로 XmlElement 노드를 복제해야 합니다.

설명

해당 이름의 특성이 요소에 이미 있는 경우 새 특성으로 대체됩니다.

적용 대상

SetAttributeNode(String, String)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

지정된 XmlAttribute를 추가합니다.

public:
 virtual System::Xml::XmlAttribute ^ SetAttributeNode(System::String ^ localName, System::String ^ namespaceURI);
public virtual System.Xml.XmlAttribute SetAttributeNode (string localName, string namespaceURI);
public virtual System.Xml.XmlAttribute SetAttributeNode (string localName, string? namespaceURI);
abstract member SetAttributeNode : string * string -> System.Xml.XmlAttribute
override this.SetAttributeNode : string * string -> System.Xml.XmlAttribute
Public Overridable Function SetAttributeNode (localName As String, namespaceURI As String) As XmlAttribute

매개 변수

localName
String

특성의 로컬 이름입니다.

namespaceURI
String

특성의 네임스페이스 URI입니다.

반환

추가할 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 xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   XmlElement^ root = doc->DocumentElement;
   
   // Add a new attribute.
   XmlAttribute^ attr = root->SetAttributeNode( "genre", "urn:samples" );
   attr->Value = "novel";
   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->InnerXml );
}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Add a new attribute.
    XmlAttribute attr = root.SetAttributeNode("genre", "urn:samples");
    attr.Value="novel";

    Console.WriteLine("Display the modified XML...");
    Console.WriteLine(doc.InnerXml);
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")

    Dim root as XmlElement = doc.DocumentElement

    ' Add a new attribute.
    Dim attr as XmlAttribute = root.SetAttributeNode("genre", "urn:samples")
    attr.Value="novel"

    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

설명

XmlAttribute 자식이 없습니다. 를 사용하여 Value 특성에 텍스트 값을 할당하거나(또는 유사한 메서드)를 사용하여 AppendChild 특성에 자식을 추가합니다.

적용 대상