다음을 통해 공유


XmlAttribute.OwnerElement 속성

특성이 속한 XmlElement를 가져옵니다.

네임스페이스: System.Xml
어셈블리: System.Xml(system.xml.dll)

구문

‘선언
Public Overridable ReadOnly Property OwnerElement As XmlElement
‘사용 방법
Dim instance As XmlAttribute
Dim value As XmlElement

value = instance.OwnerElement
public virtual XmlElement OwnerElement { get; }
public:
virtual property XmlElement^ OwnerElement {
    XmlElement^ get ();
}
/** @property */
public XmlElement get_OwnerElement ()
public function get OwnerElement () : XmlElement

속성 값

해당 특성이 속한 XmlElement이거나, 이 특성이 XmlElement의 일부가 아닌 경우 Null 참조(Visual Basic의 경우 Nothing)입니다.

예제

다음 예제에서는 특성을 만들고 이 특성의 OwnerElement를 표시합니다.

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>") 

    'Create an attribute.
    Dim attr as XmlAttribute
    attr = doc.CreateAttribute("bk","genre","urn:samples")
    attr.Value = "novel"

    'Try to display the attribute's owner element.
    if attr.OwnerElement is nothing
      Console.WriteLine("The attribute has not been added to an element")
      Console.WriteLine()
    else
      Console.WriteLine(attr.OwnerElement.OuterXml)
    end if

    'Add the attribute to an element.
    doc.DocumentElement.SetAttributeNode(attr)

    'Display the attribute's owner element.
    Console.WriteLine("Display the owner element...")
    Console.WriteLine(attr.OwnerElement.OuterXml)

  end sub
end class
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main(){

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create an attribute.
    XmlAttribute attr;
    attr = doc.CreateAttribute("bk","genre","urn:samples");
    attr.Value = "novel";

    //Try to display the attribute's owner element.
    if (attr.OwnerElement==null)
      Console.WriteLine("The attribute has not been added to an element\r\n");
    else
      Console.WriteLine(attr.OwnerElement.OuterXml);

    //Add the attribute to an element.
    doc.DocumentElement.SetAttributeNode(attr);

    //Display the attribute's owner element.
    Console.WriteLine("Display the owner element...");
    Console.WriteLine(attr.OwnerElement.OuterXml);

   }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book><title>Pride And Prejudice</title></book>" );
   
   //Create an attribute.
   XmlAttribute^ attr;
   attr = doc->CreateAttribute( "bk", "genre", "urn:samples" );
   attr->Value = "novel";
   
   //Try to display the attribute's owner element.
   if ( attr->OwnerElement == nullptr )
      Console::WriteLine( "The attribute has not been added to an element\r\n" );
   else
      Console::WriteLine( attr->OwnerElement->OuterXml );

   
   //Add the attribute to an element.
   doc->DocumentElement->SetAttributeNode( attr );
   
   //Display the attribute's owner element.
   Console::WriteLine( "Display the owner element..." );
   Console::WriteLine( attr->OwnerElement->OuterXml );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book>"
                    + "<title>Pride And Prejudice</title>"
                    + "</book>");

        //Create an attribute.
        XmlAttribute attr;
        attr = doc.CreateAttribute("bk", "genre", "urn:samples");
        attr.set_Value("novel");

        //Try to display the attribute's owner element.
        if (attr.get_OwnerElement() == null) {
            Console.WriteLine("The attribute has not been added to an"
            + " element\r\n");
        }
        else {
            Console.WriteLine(attr.get_OwnerElement().get_OuterXml());
        }

        //Add the attribute to an element.
        doc.get_DocumentElement().SetAttributeNode(attr);

        //Display the attribute's owner element.
        Console.WriteLine("Display the owner element...");
        Console.WriteLine(attr.get_OwnerElement().get_OuterXml());
    } //main
} //Sample

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

XmlAttribute 클래스
XmlAttribute 멤버
System.Xml 네임스페이스