XmlAttribute.OwnerDocument 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得這個節點所屬的 XmlDocument。
public:
virtual property System::Xml::XmlDocument ^ OwnerDocument { System::Xml::XmlDocument ^ get(); };
public override System.Xml.XmlDocument OwnerDocument { get; }
member this.OwnerDocument : System.Xml.XmlDocument
Public Overrides ReadOnly Property OwnerDocument As XmlDocument
屬性值
這個節點所屬的 XML 文件。
範例
下列範例會建立屬性並顯示其 OwnerDocument
。
#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";
//Display the attribute's owner document. Note
//that although the attribute has not been inserted
//into the document, it still has an owner document.
Console::WriteLine( attr->OwnerDocument->OuterXml );
}
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";
//Display the attribute's owner document. Note
//that although the attribute has not been inserted
//into the document, it still has an owner document.
Console.WriteLine(attr.OwnerDocument.OuterXml);
}
}
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"
'Display the attribute's owner document. Note
'that although the attribute has not been inserted
'into the document, it still has an owner document.
Console.WriteLine(attr.OwnerDocument.OuterXml)
end sub
end class