XmlAttribute.OwnerElement Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient le XmlElement auquel appartient l'attribut.
public:
virtual property System::Xml::XmlElement ^ OwnerElement { System::Xml::XmlElement ^ get(); };
public virtual System.Xml.XmlElement OwnerElement { get; }
public virtual System.Xml.XmlElement? OwnerElement { get; }
member this.OwnerElement : System.Xml.XmlElement
Public Overridable ReadOnly Property OwnerElement As XmlElement
Valeur de propriété
XmlElement
auquel appartient l'attribut, ou null
si celui-ci ne fait pas partie d'un XmlElement
.
Exemples
L’exemple suivant crée un attribut et affiche le OwnerElement
de l’attribut .
#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 );
}
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);
}
}
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
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour