XObject.Parent Proprietà

Definizione

Ottiene l'elemento padre XElement dell'oggetto XObject.

public:
 property System::Xml::Linq::XElement ^ Parent { System::Xml::Linq::XElement ^ get(); };
public System.Xml.Linq.XElement Parent { get; }
public System.Xml.Linq.XElement? Parent { get; }
member this.Parent : System.Xml.Linq.XElement
Public ReadOnly Property Parent As XElement

Valore della proprietà

Elemento padre XElement dell'oggetto XObject.

Esempio

Nell'esempio seguente viene utilizzato questo metodo.

XDocument doc = new XDocument(
    new XComment("A comment in the document."),
    new XElement("Root",
        new XElement("Child", "content")
    )
);
XElement child = doc.Descendants("Child").First();
XElement root = child.Parent;
Console.WriteLine(root.Name);
Dim doc As XDocument = _
    <?xml version="1.0"?>
    <!--A comment in the document.-->
    <Root>
        <Child>content</Child>
    </Root>
Dim child As XElement = doc.Descendants("Child").First()
Dim root As XElement = child.Parent
Console.WriteLine(root.Name)

In questo esempio viene generato l'output seguente:

Root

Commenti

Se non XObject dispone di alcun elemento padre, questa proprietà restituisce null.

Note

Questa proprietà restituisce l'elemento padre e, come nodi figlio di un XDocument elemento padre, questa proprietà restituisce null per tali nodi.

Si applica a

Vedi anche