Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
2479 lines (2192 sloc) 96.6 KB
<Type Name="XContainer" FullName="System.Xml.Linq.XContainer">
<TypeSignature Language="C#" Value="public abstract class XContainer : System.Xml.Linq.XNode" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit XContainer extends System.Xml.Linq.XNode" />
<TypeSignature Language="DocId" Value="T:System.Xml.Linq.XContainer" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class XContainer&#xA;Inherits XNode" />
<TypeSignature Language="C++ CLI" Value="public ref class XContainer abstract : System::Xml::Linq::XNode" />
<TypeSignature Language="F#" Value="type XContainer = class&#xA; inherit XNode" />
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Xml.Linq.XNode</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Represents a node that can contain other nodes.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This class provides functionality such as finding the next or previous sibling node, or enumerating the direct children of a node.
The two classes that derive from <xref:System.Xml.Linq.XContainer> are <xref:System.Xml.Linq.XDocument> and <xref:System.Xml.Linq.XElement>.
]]></format>
</remarks>
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
<related type="Article" href="https://msdn.microsoft.com/library/b8e4d9a9-a87b-4010-871a-67fd95b50e2b">How to: Retrieve Elements at a Particular Depth</related>
</Docs>
<Members>
<MemberGroup MemberName="Add">
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Adds the specified content as children to this <see cref="T:System.Xml.Linq.XContainer" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content after the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, and then uses this method to add the results of a query to one of them.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("NewElement", "Content")
);
xmlTree.Add(
from el in srcTree.Elements()
where (int)el >= 3
select el
);
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<NewElement>Content</NewElement>
</Root>
xmlTree.Add( _
From el In srcTree.Elements _
Where CInt(el) >= 3 _
Select el)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<NewElement>Content</NewElement>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.AddFirst" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</MemberGroup>
<Member MemberName="Add">
<MemberSignature Language="C#" Value="public void Add (object content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Add(object content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Add(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub Add (content As Object)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void Add(System::Object ^ content);" />
<MemberSignature Language="F#" Value="member this.Add : obj -&gt; unit" Usage="xContainer.Add content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object" />
</Parameters>
<Docs>
<param name="content">A content object containing simple content or a collection of content objects to be added.</param>
<summary>Adds the specified content as children of this <see cref="T:System.Xml.Linq.XContainer" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content after the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, and then uses this method to add an <xref:System.Xml.Linq.XElement> object to one of them. It also adds the results of a [!INCLUDE[vbteclinq](~/includes/vbteclinq-md.md)] query to the XML tree.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
xmlTree.Add(new XElement("NewChild", "new content"));
xmlTree.Add(
from el in srcTree.Elements()
where (int)el > 3
select el
);
// Even though Child9 does not exist in srcTree, the following statement will not
// throw an exception, and nothing will be added to xmlTree.
xmlTree.Add(srcTree.Element("Child9"));
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
xmlTree.Add(New XElement("NewChild", "new content"))
xmlTree.Add( _
From el In srcTree.Elements() _
Where CInt(el) > 3 _
Select el _
)
' Even though Child9 does not exist in srcTree, the following statement will not
' throw an exception, and nothing will be added to xmlTree.
xmlTree.Add(srcTree.<Child9>)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
<NewChild>new content</NewChild>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.AddFirst" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="Add">
<MemberSignature Language="C#" Value="public void Add (params object[] content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Add(object[] content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Add(System.Object[])" />
<MemberSignature Language="VB.NET" Value="Public Sub Add (ParamArray content As Object())" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void Add(... cli::array &lt;System::Object ^&gt; ^ content);" />
<MemberSignature Language="F#" Value="member this.Add : obj[] -&gt; unit" Usage="xContainer.Add content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object[]">
<Attributes>
<Attribute FrameworkAlternate="dotnet-uwp-10.0">
<AttributeName>System.ParamArray</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="content">A parameter list of content objects.</param>
<summary>Adds the specified content as children of this <see cref="T:System.Xml.Linq.XContainer" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content after the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, uses this method to add an <xref:System.Xml.Linq.XElement> object to one of them. It also adds the results of a [!INCLUDE[vbteclinq](~/includes/vbteclinq-md.md)] query to the XML tree.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
xmlTree.Add(new XElement("NewChild", "new content"));
xmlTree.Add(
from el in srcTree.Elements()
where (int)el > 3
select el
);
// Even though Child9 does not exist in srcTree, the following statement will not
// throw an exception, and nothing will be added to xmlTree
xmlTree.Add(srcTree.Element("Child9"));
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
xmlTree.Add(New XElement("NewChild", "new content"))
xmlTree.Add( _
From el In srcTree.Elements() _
Where CInt(el) > 3 _
Select el _
)
' Even though Child9 does not exist in srcTree, the following statement will not
' throw an exception, and nothing will be added to xmlTree
xmlTree.Add(srcTree.<Child9>)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
<NewChild>new content</NewChild>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.AddFirst" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<MemberGroup MemberName="AddFirst">
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Adds the specified content as the first children of this document or element.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content before the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, and then uses this method to add the results of a query to one of them.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("NewElement", "Content")
);
xmlTree.AddFirst(
from el in srcTree.Elements()
where (int)el >= 3
select el
);
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = <Root>
<NewElement>Content</NewElement>
</Root>
xmlTree.AddFirst( _
From el In srcTree.Elements _
Where CInt(el) >= 3 _
Select el)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
<NewElement>Content</NewElement>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</MemberGroup>
<Member MemberName="AddFirst">
<MemberSignature Language="C#" Value="public void AddFirst (object content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void AddFirst(object content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.AddFirst(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub AddFirst (content As Object)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void AddFirst(System::Object ^ content);" />
<MemberSignature Language="F#" Value="member this.AddFirst : obj -&gt; unit" Usage="xContainer.AddFirst content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object" />
</Parameters>
<Docs>
<param name="content">A content object containing simple content or a collection of content objects to be added.</param>
<summary>Adds the specified content as the first children of this document or element.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content before the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, uses this method to add an <xref:System.Xml.Linq.XElement> object as the first element to one of them. It also adds the results of a [!INCLUDE[vbteclinq](~/includes/vbteclinq-md.md)] query to the XML tree.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
xmlTree.AddFirst(new XElement("NewChild", "new content"));
xmlTree.AddFirst(
from el in srcTree.Elements()
where (int)el > 3
select el
);
// Even though Child9 does not exist in srcTree, the following statement will not
// throw an exception, and nothing will be added to xmlTree
xmlTree.AddFirst(srcTree.Element("Child9"));
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
xmlTree.AddFirst(New XElement("NewChild", "new content"))
xmlTree.AddFirst( _
From el In srcTree.Elements() _
Where CInt(el) > 3 _
Select el _
)
' Even though Child9 does not exist in srcTree, the following statement will not
' throw an exception, and nothing will be added to xmlTree
xmlTree.AddFirst(srcTree.<Child9>)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Element4>4</Element4>
<Element5>5</Element5>
<NewChild>new content</NewChild>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="AddFirst">
<MemberSignature Language="C#" Value="public void AddFirst (params object[] content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void AddFirst(object[] content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.AddFirst(System.Object[])" />
<MemberSignature Language="VB.NET" Value="Public Sub AddFirst (ParamArray content As Object())" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void AddFirst(... cli::array &lt;System::Object ^&gt; ^ content);" />
<MemberSignature Language="F#" Value="member this.AddFirst : obj[] -&gt; unit" Usage="xContainer.AddFirst content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object[]">
<Attributes>
<Attribute FrameworkAlternate="dotnet-uwp-10.0">
<AttributeName>System.ParamArray</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="content">A parameter list of content objects.</param>
<summary>Adds the specified content as the first children of this document or element.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method adds the new content before the existing content of the <xref:System.Xml.Linq.XContainer>.
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates two XML trees, and uses this method to add an <xref:System.Xml.Linq.XElement> object as the first element to one of them. It also adds the results of a [!INCLUDE[vbteclinq](~/includes/vbteclinq-md.md)] query to the XML tree.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
xmlTree.AddFirst(new XElement("NewChild", "new content"));
xmlTree.AddFirst(
from el in srcTree.Elements()
where (int)el > 3
select el
);
// Even though Child9 does not exist in srcTree, the following statement will not
// throw an exception, and nothing will be added to xmlTree.
xmlTree.AddFirst(srcTree.Element("Child9"));
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
xmlTree.AddFirst(New XElement("NewChild", "new content"))
xmlTree.AddFirst( _
From el In srcTree.Elements() _
Where CInt(el) > 3 _
Select el _
)
' Even though Child9 does not exist in srcTree, the following statement will not
' throw an exception, and nothing will be added to xmlTree.
xmlTree.AddFirst(srcTree.<Child9>)
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Element4>4</Element4>
<Element5>5</Element5>
<NewChild>new content</NewChild>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
```
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The parent is <see langword="null" />.</exception>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="CreateWriter">
<MemberSignature Language="C#" Value="public System.Xml.XmlWriter CreateWriter ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Xml.XmlWriter CreateWriter() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.CreateWriter" />
<MemberSignature Language="VB.NET" Value="Public Function CreateWriter () As XmlWriter" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Xml::XmlWriter ^ CreateWriter();" />
<MemberSignature Language="F#" Value="member this.CreateWriter : unit -&gt; System.Xml.XmlWriter" Usage="xContainer.CreateWriter " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Xml.XmlWriter</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Creates an <see cref="T:System.Xml.XmlWriter" /> that can be used to add nodes to the <see cref="T:System.Xml.Linq.XContainer" />.</summary>
<returns>An <see cref="T:System.Xml.XmlWriter" /> that is ready to have content written to it.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
While serializing, namespace prefixes are inferred from the namespace attributes in the XML tree.
For more information, see [Working with XML Namespaces](https://msdn.microsoft.com/library/e3003209-3234-45be-a832-47feb7927430).
## Examples
You can use this method to perform an XSLT transformation. You can create an XML tree, create an <xref:System.Xml.XmlReader> from the XML tree, create a new document, and create a <xref:System.Xml.XmlWriter> that will write into the new document. Then, you can invoke the XSLT transformation, passing the <xref:System.Xml.XmlReader> and <xref:System.Xml.XmlWriter> to the transform. After the transformation successfully completes, the new XML tree is populated with the results of the transformation.
```csharp
string xslMarkup = @"<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:template match='/Parent'>
<Root>
<C1><xsl:value-of select='Child1'/></C1>
<C2><xsl:value-of select='Child2'/></C2>
</Root>
</xsl:template>
</xsl:stylesheet>";
XDocument xmlTree = new XDocument(
new XElement("Parent",
new XElement("Child1", "Child1 data"),
new XElement("Child2", "Child2 data")
)
);
XDocument newTree = new XDocument();
using (XmlWriter writer = newTree.CreateWriter()) {
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(new StringReader(xslMarkup)));
// Execute the transform and output the results to a writer.
xslt.Transform(xmlTree.CreateReader(), writer);
}
Console.WriteLine(newTree);
```
```vb
Dim xslMarkup As XDocument = _
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:template match='/Parent'>
<Root>
<C1><xsl:value-of select='Child1'/></C1>
<C2><xsl:value-of select='Child2'/></C2>
</Root>
</xsl:template>
</xsl:stylesheet>
Dim xmlTree As XElement = _
<Parent>
<Child1>Child1 data</Child1>
<Child2>Child2 data</Child2>
</Parent>
Dim newTree As XDocument = New XDocument()
Using writer As XmlWriter = newTree.CreateWriter()
' Load the style sheet.
Dim xslt As XslCompiledTransform = _
New XslCompiledTransform()
xslt.Load(xslMarkup.CreateReader())
' Execute the transform and output the results to a writer.
xslt.Transform(xmlTree.CreateReader(), writer)
End Using
Console.WriteLine(newTree)
```
This example produces the following output:
```xml
<Root>
<C1>Child1 data</C1>
<C2>Child2 data</C2>
</Root>
```
]]></format>
</remarks>
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
<related type="Article" href="https://msdn.microsoft.com/library/f01bdf96-c5a9-4859-b220-125ee531e71f">Serializing XML Trees</related>
</Docs>
</Member>
<Member MemberName="DescendantNodes">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XNode&gt; DescendantNodes ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XNode&gt; DescendantNodes() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.DescendantNodes" />
<MemberSignature Language="VB.NET" Value="Public Function DescendantNodes () As IEnumerable(Of XNode)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XNode ^&gt; ^ DescendantNodes();" />
<MemberSignature Language="F#" Value="member this.DescendantNodes : unit -&gt; seq&lt;System.Xml.Linq.XNode&gt;" Usage="xContainer.DescendantNodes " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XNode&gt;</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a collection of the descendant nodes for this document or element, in document order.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XNode" /> containing the descendant nodes of the <see cref="T:System.Xml.Linq.XContainer" />, in document order.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Note that attributes are not considered to be nodes in [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], so they will not be part of the collection that is returned by this method.
This method uses deferred execution.
## Examples
The following example creates an XML tree, and then iterates through the <xref:System.Xml.Linq.XContainer.DescendantNodes%2A> axis.
```csharp
XElement xmlTree = new XElement("Root",
// Attributes are not nodes, so will not be returned by DescendantNodes.
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XElement("GrandChild", "element content")
)
);
IEnumerable<XNode> dnas =
from node in xmlTree.DescendantNodes()
select node;
foreach (XNode node in dnas)
{
if (node is XElement)
Console.WriteLine((node as XElement).Name);
else
Console.WriteLine(node);
}
```
```vb
' Attributes are not nodes, so will not be returned by DescendantNodes.
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim dnas = From node In xmlTree.DescendantNodes _
Select node
For Each node In dnas
If TypeOf node Is XElement Then
Console.WriteLine(DirectCast(node, XElement).Name)
Else
Console.WriteLine(node)
End If
Next
```
This example produces the following output:
```
Child
GrandChild
element content
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Descendants" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Elements" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<MemberGroup MemberName="Descendants">
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a collection of the descendant elements for this document or element, in document order.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method uses deferred execution.
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Elements" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</MemberGroup>
<Member MemberName="Descendants">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt; Descendants ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XElement&gt; Descendants() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Descendants" />
<MemberSignature Language="VB.NET" Value="Public Function Descendants () As IEnumerable(Of XElement)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XElement ^&gt; ^ Descendants();" />
<MemberSignature Language="F#" Value="member this.Descendants : unit -&gt; seq&lt;System.Xml.Linq.XElement&gt;" Usage="xContainer.Descendants " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt;</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a collection of the descendant elements for this document or element, in document order.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XElement" /> containing the descendant elements of the <see cref="T:System.Xml.Linq.XContainer" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Note that this method will not return itself in the resulting <xref:System.Collections.Generic.IEnumerable%601>. See <xref:System.Xml.Linq.XElement.DescendantsAndSelf%2A> if you need to include the current <xref:System.Xml.Linq.XElement> in the results.
This method uses deferred execution.
## Examples
The following example creates an XML tree, and then uses this axis method to retrieve the descendants.
```csharp
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XElement> de =
from el in xmlTree.Descendants()
select el;
foreach (XElement el in de)
Console.WriteLine(el.Name);
```
```vb
' Attributes are not nodes, so will not be returned by DescendantNodes.
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim de = From el In xmlTree.Descendants _
Select el
For Each el In de
Console.WriteLine(el.Name)
Next
```
This example produces the following output:
```
Child
GrandChild
```
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XElement.DescendantsAndSelf" />
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Elements" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="Descendants">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt; Descendants (System.Xml.Linq.XName name);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XElement&gt; Descendants(class System.Xml.Linq.XName name) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Descendants(System.Xml.Linq.XName)" />
<MemberSignature Language="VB.NET" Value="Public Function Descendants (name As XName) As IEnumerable(Of XElement)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XElement ^&gt; ^ Descendants(System::Xml::Linq::XName ^ name);" />
<MemberSignature Language="F#" Value="member this.Descendants : System.Xml.Linq.XName -&gt; seq&lt;System.Xml.Linq.XElement&gt;" Usage="xContainer.Descendants name" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt;</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="name" Type="System.Xml.Linq.XName" />
</Parameters>
<Docs>
<param name="name">The <see cref="T:System.Xml.Linq.XName" /> to match.</param>
<summary>Returns a filtered collection of the descendant elements for this document or element, in document order. Only elements that have a matching <see cref="T:System.Xml.Linq.XName" /> are included in the collection.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XElement" /> containing the descendant elements of the <see cref="T:System.Xml.Linq.XContainer" /> that match the specified <see cref="T:System.Xml.Linq.XName" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method uses deferred execution.
## Examples
The following example prints all descendants of an element.
```csharp
// Attributes are not nodes, so will not be returned by DescendantNodes.
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XElement> de =
from el in xmlTree.Descendants("Child")
select el;
foreach (XElement el in de)
Console.WriteLine(el.Name);
```
```vb
' Attributes are not nodes, so will not be returned by the descendants axis.
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim de = From el In xmlTree...<Child> _
Select el
For Each el In de
Console.WriteLine(el.Name)
Next
```
This example produces the following output:
```
Child
```
The following is the same example, but in this case the XML is in a namespace. For more information, see [Working with XML Namespaces](https://msdn.microsoft.com/library/e3003209-3234-45be-a832-47feb7927430).
```csharp
// Attributes are not nodes, so will not be returned by DescendantNodes.
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
new XAttribute(aw + "Att1", "AttributeContent"),
new XElement(aw + "Child",
new XText("Some text"),
new XElement(aw + "GrandChild", "element content")
)
);
IEnumerable<XElement> de =
from el in xmlTree.Descendants(aw + "Child")
select el;
foreach (XElement el in de)
Console.WriteLine(el.Name);
```
```vb
Imports <xmlns:aw = "http://www.adventure-works.com">
Module Module1
Sub Main()
' Attributes are not nodes, so will not be returned by the descendants axis.
Dim xmlTree As XElement = _
<aw:Root aw:Att1="AttributeContent">
<aw:Child>Some text
<aw:GrandChild>element content</aw:GrandChild>
</aw:Child>
</aw:Root>
Dim de = From el In xmlTree...<aw:Child> _
Select el
For Each el In de
Console.WriteLine(el.Name)
Next
End Sub
End Module
```
This example produces the following output:
```
{http://www.adventure-works.com}Child
```
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Elements" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="Element">
<MemberSignature Language="C#" Value="public System.Xml.Linq.XElement Element (System.Xml.Linq.XName name);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Xml.Linq.XElement Element(class System.Xml.Linq.XName name) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Element(System.Xml.Linq.XName)" />
<MemberSignature Language="VB.NET" Value="Public Function Element (name As XName) As XElement" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Xml::Linq::XElement ^ Element(System::Xml::Linq::XName ^ name);" />
<MemberSignature Language="F#" Value="member this.Element : System.Xml.Linq.XName -&gt; System.Xml.Linq.XElement" Usage="xContainer.Element name" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Xml.Linq.XElement</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="name" Type="System.Xml.Linq.XName" />
</Parameters>
<Docs>
<param name="name">The <see cref="T:System.Xml.Linq.XName" /> to match.</param>
<summary>Gets the first (in document order) child element with the specified <see cref="T:System.Xml.Linq.XName" />.</summary>
<returns>A <see cref="T:System.Xml.Linq.XElement" /> that matches the specified <see cref="T:System.Xml.Linq.XName" />, or <see langword="null" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Returns `null` if there is no element with the specified name.
Some axis methods return collections of elements or attributes. This method returns only a single element.
This method returns `null` if the element with the specified name is not found. All of the methods that allow you to construct elements (the constructor of <xref:System.Xml.Linq.XElement>, <xref:System.Xml.Linq.XContainer.Add%2A>, and so on) accept `null` as a valid argument. This allows you to use a convenient idiom: you can call this method as part of functional construction, and the element is added to the XML tree being constructed if and only if the element exists in the source tree. The following example shows this idiom.
In contrast to <xref:System.Xml.Linq.XContainer.Elements%2A>, this method is not an axis method. It does not use deferred execution; it simply returns an element when called.
## Examples
The following example shows two uses of this method. In one case, the method finds the element in `srcTree`. In the second case, the method does not find the element in the source tree, no element is added to `xmlTree`, and no exception is thrown.
Note that the Visual Basic example uses the child XML property. It is also allowable to use the <xref:System.Xml.Linq.XContainer.Element%2A> method directly in Visual Basic.
```csharp
XElement srcTree = new XElement("Root",
new XElement("Element1", 1),
new XElement("Element2", 2),
new XElement("Element3", 3),
new XElement("Element4", 4),
new XElement("Element5", 5)
);
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5),
srcTree.Element("Element3"),
// Even though Element9 does not exist in srcTree, the following line
// will not throw an exception.
srcTree.Element("Element9")
);
Console.WriteLine(xmlTree);
```
```vb
Dim srcTree As XElement = _
<Root>
<Element1>1</Element1>
<Element2>2</Element2>
<Element3>3</Element3>
<Element4>4</Element4>
<Element5>5</Element5>
</Root>
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
<%= srcTree.<Element3> %>
<%= srcTree.<Element9> %>
</Root>
' Even though Element9 does not exist in srcTree, adding it to the tree
' will not throw an exception.
Console.WriteLine(xmlTree)
```
This example produces the following output:
```xml
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
<Element3>3</Element3>
</Root>
```
The following is the same example, but in this case the XML is in a namespace. For more information, see [Working with XML Namespaces](https://msdn.microsoft.com/library/e3003209-3234-45be-a832-47feb7927430).
```csharp
XNamespace aw = "http://www.adventure-works.com";
XElement srcTree = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XElement(aw + "Element1", 1),
new XElement(aw + "Element2", 2),
new XElement(aw + "Element3", 3),
new XElement(aw + "Element4", 4),
new XElement(aw + "Element5", 5)
);
XElement xmlTree = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XElement(aw + "Child1", 1),
new XElement(aw + "Child2", 2),
new XElement(aw + "Child3", 3),
new XElement(aw + "Child4", 4),
new XElement(aw + "Child5", 5),
srcTree.Element(aw + "Element3"),
// Even though Element9 does not exist in srcTree, the following line
// will not throw an exception.
srcTree.Element(aw + "Element9")
);
Console.WriteLine(xmlTree);
```
```vb
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim srcTree As XElement = _
<aw:Root>
<aw:Element1>1</aw:Element1>
<aw:Element2>2</aw:Element2>
<aw:Element3>3</aw:Element3>
<aw:Element4>4</aw:Element4>
<aw:Element5>5</aw:Element5>
</aw:Root>
Dim xmlTree As XElement = _
<aw:Root>
<aw:Child1>1</aw:Child1>
<aw:Child2>2</aw:Child2>
<aw:Child3>3</aw:Child3>
<aw:Child4>4</aw:Child4>
<aw:Child5>5</aw:Child5>
<%= srcTree.<aw:Element3> %>
<%= srcTree.<aw:Element9> %>
</aw:Root>
' Even though Element9 does not exist in srcTree, adding it to the tree
' will not throw an exception.
Console.WriteLine(xmlTree)
End Sub
End Module
```
This example produces the following output:
```xml
<aw:Root xmlns:aw="http://www.adventure-works.com">
<aw:Child1>1</aw:Child1>
<aw:Child2>2</aw:Child2>
<aw:Child3>3</aw:Child3>
<aw:Child4>4</aw:Child4>
<aw:Child5>5</aw:Child5>
<aw:Element3>3</aw:Element3>
</aw:Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Elements" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<MemberGroup MemberName="Elements">
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a collection of the child elements of this element or document, in document order.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method uses deferred execution.
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XContainer.Element(System.Xml.Linq.XName)" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Descendants" />
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</MemberGroup>
<Member MemberName="Elements">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt; Elements ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XElement&gt; Elements() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Elements" />
<MemberSignature Language="VB.NET" Value="Public Function Elements () As IEnumerable(Of XElement)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XElement ^&gt; ^ Elements();" />
<MemberSignature Language="F#" Value="member this.Elements : unit -&gt; seq&lt;System.Xml.Linq.XElement&gt;" Usage="xContainer.Elements " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt;</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a collection of the child elements of this element or document, in document order.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XElement" /> containing the child elements of this <see cref="T:System.Xml.Linq.XContainer" />, in document order.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method uses deferred execution.
## Examples
The following example creates an XML tree, and then selects some elements using this axis method.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
IEnumerable<XElement> elements =
from el in xmlTree.Elements()
where (int)el <= 3
select el;
foreach (XElement el in elements)
Console.WriteLine(el);
```
```vb
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
Dim elements = From el In xmlTree.Elements _
Where el.Value <= 3 _
Select el
For Each el In elements
Console.WriteLine(el)
Next
```
This example produces the following output:
```
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
```
The following is the same example, but in this case the XML is in a namespace. For more information, see [Working with XML Namespaces](https://msdn.microsoft.com/library/e3003209-3234-45be-a832-47feb7927430).
```csharp
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XElement(aw + "Child1", 1),
new XElement(aw + "Child2", 2),
new XElement(aw + "Child3", 3),
new XElement(aw + "Child4", 4),
new XElement(aw + "Child5", 5)
);
IEnumerable<XElement> elements =
from el in xmlTree.Elements()
where (int)el <= 3
select el;
foreach (XElement el in elements)
Console.WriteLine(el);
```
```vb
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = _
<aw:Root>
<aw:Child1>1</aw:Child1>
<aw:Child2>2</aw:Child2>
<aw:Child3>3</aw:Child3>
<aw:Child4>4</aw:Child4>
<aw:Child5>5</aw:Child5>
</aw:Root>
Dim elements = From el In xmlTree.Elements _
Where el.Value <= 3 _
Select el
For Each el In elements
Console.WriteLine(el)
Next
End Sub
End Module
```
This example produces the following output:
```
<aw:Child1 xmlns:aw="http://www.adventure-works.com">1</aw:Child1>
<aw:Child2 xmlns:aw="http://www.adventure-works.com">2</aw:Child2>
<aw:Child3 xmlns:aw="http://www.adventure-works.com">3</aw:Child3>
```
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XContainer.Element(System.Xml.Linq.XName)" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Descendants" />
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="Elements">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt; Elements (System.Xml.Linq.XName name);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XElement&gt; Elements(class System.Xml.Linq.XName name) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Elements(System.Xml.Linq.XName)" />
<MemberSignature Language="VB.NET" Value="Public Function Elements (name As XName) As IEnumerable(Of XElement)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XElement ^&gt; ^ Elements(System::Xml::Linq::XName ^ name);" />
<MemberSignature Language="F#" Value="member this.Elements : System.Xml.Linq.XName -&gt; seq&lt;System.Xml.Linq.XElement&gt;" Usage="xContainer.Elements name" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XElement&gt;</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="name" Type="System.Xml.Linq.XName" />
</Parameters>
<Docs>
<param name="name">The <see cref="T:System.Xml.Linq.XName" /> to match.</param>
<summary>Returns a filtered collection of the child elements of this element or document, in document order. Only elements that have a matching <see cref="T:System.Xml.Linq.XName" /> are included in the collection.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XElement" /> containing the children of the <see cref="T:System.Xml.Linq.XContainer" /> that have a matching <see cref="T:System.Xml.Linq.XName" />, in document order.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method uses deferred execution.
## Examples
The following example creates an XML tree, and then selects several child elements using this axis method.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Type1", 1),
new XElement("Type1", 2),
new XElement("Type2", 3),
new XElement("Type2", 4),
new XElement("Type2", 5)
);
IEnumerable<XElement> elements =
from el in xmlTree.Elements("Type2")
select el;
foreach (XElement el in elements)
Console.WriteLine(el);
```
```vb
Dim xmlTree As XElement = _
<Root>
<Type1>1</Type1>
<Type1>2</Type1>
<Type2>3</Type2>
<Type2>4</Type2>
<Type2>5</Type2>
</Root>
Dim elements = From el In xmlTree.<Type2> _
Select el
For Each el In elements
Console.WriteLine(el)
Next
```
This example produces the following output:
```
<Type2>3</Type2>
<Type2>4</Type2>
<Type2>5</Type2>
```
The following is the same example, but in this case the XML is in a namespace. For more information, see [Working with XML Namespaces](https://msdn.microsoft.com/library/e3003209-3234-45be-a832-47feb7927430).
```csharp
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XElement(aw + "Type1", 1),
new XElement(aw + "Type1", 2),
new XElement(aw + "Type2", 3),
new XElement(aw + "Type2", 4),
new XElement(aw + "Type2", 5)
);
IEnumerable<XElement> elements =
from el in xmlTree.Elements(aw + "Type2")
select el;
foreach (XElement el in elements)
Console.WriteLine(el);
```
```vb
Imports <xmlns:aw="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = _
<aw:Root>
<aw:Type1>1</aw:Type1>
<aw:Type1>2</aw:Type1>
<aw:Type2>3</aw:Type2>
<aw:Type2>4</aw:Type2>
<aw:Type2>5</aw:Type2>
</aw:Root>
Dim elements = From el In xmlTree.<aw:Type2> _
Select el
For Each el In elements
Console.WriteLine(el)
Next
End Sub
End Module
```
This example produces the following output:
```
<aw:Type2 xmlns:aw="http://www.adventure-works.com">3</aw:Type2>
<aw:Type2 xmlns:aw="http://www.adventure-works.com">4</aw:Type2>
<aw:Type2 xmlns:aw="http://www.adventure-works.com">5</aw:Type2>
```
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XContainer.Element(System.Xml.Linq.XName)" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Descendants" />
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="FirstNode">
<MemberSignature Language="C#" Value="public System.Xml.Linq.XNode FirstNode { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Xml.Linq.XNode FirstNode" />
<MemberSignature Language="DocId" Value="P:System.Xml.Linq.XContainer.FirstNode" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property FirstNode As XNode" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Xml::Linq::XNode ^ FirstNode { System::Xml::Linq::XNode ^ get(); };" />
<MemberSignature Language="F#" Value="member this.FirstNode : System.Xml.Linq.XNode" Usage="System.Xml.Linq.XContainer.FirstNode" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Xml.Linq.XNode</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the first child node of this node.</summary>
<value>An <see cref="T:System.Xml.Linq.XNode" /> containing the first child node of the <see cref="T:System.Xml.Linq.XContainer" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Examples
The following example creates an element that contains child elements. It then gets the first child node of the parent element.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
XNode firstNode = xmlTree.FirstNode;
Console.WriteLine(firstNode);
```
```vb
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
Dim firstNode As XNode = xmlTree.FirstNode
Console.WriteLine(firstNode)
```
This example produces the following output:
```xml
<Child1>1</Child1>
```
]]></format>
</remarks>
<altmember cref="P:System.Xml.Linq.XContainer.LastNode" />
<altmember cref="M:System.Xml.Linq.XContainer.Nodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="LastNode">
<MemberSignature Language="C#" Value="public System.Xml.Linq.XNode LastNode { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Xml.Linq.XNode LastNode" />
<MemberSignature Language="DocId" Value="P:System.Xml.Linq.XContainer.LastNode" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property LastNode As XNode" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Xml::Linq::XNode ^ LastNode { System::Xml::Linq::XNode ^ get(); };" />
<MemberSignature Language="F#" Value="member this.LastNode : System.Xml.Linq.XNode" Usage="System.Xml.Linq.XContainer.LastNode" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Xml.Linq.XNode</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the last child node of this node.</summary>
<value>An <see cref="T:System.Xml.Linq.XNode" /> containing the last child node of the <see cref="T:System.Xml.Linq.XContainer" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Examples
The following example creates an element that contains child elements. It then gets the last child node of the parent element.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5)
);
XNode lastNode = xmlTree.LastNode;
Console.WriteLine(lastNode);
```
```vb
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
Dim lastNode As XNode = xmlTree.LastNode
Console.WriteLine(lastNode)
```
This example produces the following output:
```xml
<Child5>5</Child5>
```
]]></format>
</remarks>
<altmember cref="P:System.Xml.Linq.XContainer.FirstNode" />
<altmember cref="M:System.Xml.Linq.XContainer.Nodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="Nodes">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XNode&gt; Nodes ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Collections.Generic.IEnumerable`1&lt;class System.Xml.Linq.XNode&gt; Nodes() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.Nodes" />
<MemberSignature Language="VB.NET" Value="Public Function Nodes () As IEnumerable(Of XNode)" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.6;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Collections::Generic::IEnumerable&lt;System::Xml::Linq::XNode ^&gt; ^ Nodes();" />
<MemberSignature Language="F#" Value="member this.Nodes : unit -&gt; seq&lt;System.Xml.Linq.XNode&gt;" Usage="xContainer.Nodes " />
<MemberSignature Language="VB.NET" Value="Public Iterator Function Nodes () As IEnumerable(Of XNode)" FrameworkAlternate="netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.6">
<AttributeName>System.Runtime.CompilerServices.IteratorStateMachine(typeof(System.Xml.Linq.XContainer/&lt;Nodes&gt;d__1))</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8">
<AttributeName>System.Runtime.CompilerServices.IteratorStateMachine(typeof(System.Xml.Linq.XContainer/&lt;Nodes&gt;d__18))</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Generic.IEnumerable&lt;System.Xml.Linq.XNode&gt;</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a collection of the child nodes of this element or document, in document order.</summary>
<returns>An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Xml.Linq.XNode" /> containing the contents of this <see cref="T:System.Xml.Linq.XContainer" />, in document order.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Note that the content does not include attributes. In [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], attributes are not considered to be nodes of the tree. They are name/value pairs associated with an element.
This method uses deferred execution.
## Examples
The following example creates an XML tree with a variety of types of nodes. It then queries this axis method to enumerate and print the nodes.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XComment("a comment"),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XText("mixed content"),
new XElement("Child5", 5)
);
IEnumerable<XNode> nodes =
from nd in xmlTree.Nodes()
select nd;
foreach (XNode node in nodes)
Console.WriteLine(node);
```
```vb
Dim xmlTree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<!--a comment-->
<Child3>3</Child3>
<Child4>4</Child4>mixed content<Child5>5</Child5>
</Root>
Dim nodes = From nd In xmlTree.Nodes() _
Select nd
For Each node In nodes
Console.WriteLine(node)
Next
```
This example produces the following output:
```
<Child1>1</Child1>
<Child2>2</Child2>
<!--a comment-->
<Child3>3</Child3>
<Child4>4</Child4>
mixed content
<Child5>5</Child5>
```
The following example creates an XML tree that contains a variety of types of nodes. It then enumerates through portions of the tree, printing the node types.
```csharp
XDocument xmlTree = new XDocument(
new XComment("a comment"),
new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"hello.xsl\""),
new XElement("Root",
new XAttribute("Att", "attContent"),
new XElement("Child1",
new XCData("CDATA content")
),
new XElement("Child2",
new XText("Text content")
)
)
);
foreach (XNode node in xmlTree.Nodes())
{
Console.WriteLine(node.NodeType);
if (node.NodeType == XmlNodeType.Element)
{
foreach (XAttribute att in ((XElement)node).Attributes())
Console.WriteLine(att.NodeType);
foreach (XNode node2 in ((XElement)node).Nodes())
{
Console.WriteLine(node2.NodeType);
if (node2.NodeType == XmlNodeType.Element)
foreach (XNode node3 in ((XElement)node2).Nodes())
Console.WriteLine(node3.NodeType);
}
}
}
```
```vb
Dim xmlTree As XDocument = _
<?xml version="1.0" encoding="utf-8"?>
<!--a comment-->
<?xml-stylesheet type='text/xsl' href='hello.xsl'?>
<Root Att="attContent">
<Child1><![CDATA[CDATA content]]]><![CDATA[]></Child1>
<Child2>Text content</Child2>
</Root>
' Note that XNode uses XmlNodeType, which is in the System.Xml namespace
For Each node In xmlTree.Nodes
Console.WriteLine(node.NodeType.ToString())
If node.NodeType = XmlNodeType.Element Then
For Each att In DirectCast(node, XElement).Attributes
Console.WriteLine(att.NodeType.ToString())
Next
For Each node2 In DirectCast (node, XElement).Nodes()
Console.WriteLine(node2.NodeType.ToString())
If node2.NodeType = XmlNodeType.Element Then
For Each node3 In DirectCast (node2, XElement).Nodes
Console.WriteLine(node3.NodeType.ToString())
Next
End If
Next
End If
Next
```
This example produces the following output:
```
Comment
ProcessingInstruction
Element
Attribute
Element
CDATA
Element
Text
```
]]></format>
</remarks>
<altmember cref="M:System.Xml.Linq.XElement.Attributes" />
<altmember cref="Overload:System.Xml.Linq.XContainer.Descendants" />
<altmember cref="M:System.Xml.Linq.XContainer.DescendantNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="RemoveNodes">
<MemberSignature Language="C#" Value="public void RemoveNodes ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void RemoveNodes() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.RemoveNodes" />
<MemberSignature Language="VB.NET" Value="Public Sub RemoveNodes ()" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void RemoveNodes();" />
<MemberSignature Language="F#" Value="member this.RemoveNodes : unit -&gt; unit" Usage="xContainer.RemoveNodes " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Removes the child nodes from this document or element.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If you call this method on an element that contains attributes, this method will not remove the attributes. To remove the attributes of an element, use <xref:System.Xml.Linq.XElement.RemoveAttributes%2A>.
The <xref:System.Xml.Linq.Extensions.Remove%2A> method has related functionality. It removes the child nodes of every node in a collection.
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
## Examples
The following example creates an XML tree that contains some child nodes. It then calls this method to remove the child nodes.
```csharp
XElement xmlTree = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XComment("a comment"),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XText("mixed content"),
new XElement("Child5", 5)
);
xmlTree.RemoveNodes();
Console.WriteLine(xmlTree);
```
```vb
Dim xmltree As XElement = _
<Root>
<Child1>1</Child1>
<Child2>2</Child2>
<!--a comment-->
<Child3>3</Child3>
<Child4>4</Child4>mixed content<Child5>5</Child5>
</Root>
xmltree.RemoveNodes()
Console.WriteLine(xmltree)
```
This example produces the following output:
```xml
<Root />
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="Overload:System.Xml.Linq.XContainer.ReplaceNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<MemberGroup MemberName="ReplaceNodes">
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Replaces the children nodes of this document or element with the specified content.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
This method has snapshot semantics. It first creates a copy of the new content. It then removes all children nodes of this node. Finally, it adds the new content as children nodes. This means that you can replace children nodes using a query on the children nodes themselves.
## Examples
The following example creates two XML trees, and then uses this method to replace the contents of one of them with the results of a query.
```csharp
XElement root = new XElement("Root",
new XElement("Child", 1),
new XElement("Child", 2),
new XElement("Child", 3),
new XElement("Child", 4),
new XElement("Child", 5)
);
root.ReplaceNodes(
from el in root.Elements()
where (int)el >= 3
select el
);
Console.WriteLine(root);
```
```vb
Dim root As XElement = _
<Root>
<Child>1</Child>
<Child>2</Child>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
root.ReplaceNodes( _
From el In root.Elements _
Where el.Value >= 3 _
Select el)
Console.WriteLine(root)
```
This example produces the following output:
```xml
<Root>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</MemberGroup>
<Member MemberName="ReplaceNodes">
<MemberSignature Language="C#" Value="public void ReplaceNodes (object content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void ReplaceNodes(object content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.ReplaceNodes(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub ReplaceNodes (content As Object)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void ReplaceNodes(System::Object ^ content);" />
<MemberSignature Language="F#" Value="member this.ReplaceNodes : obj -&gt; unit" Usage="xContainer.ReplaceNodes content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object" />
</Parameters>
<Docs>
<param name="content">A content object containing simple content or a collection of content objects that replace the children nodes.</param>
<summary>Replaces the children nodes of this document or element with the specified content.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
This method has snapshot semantics. It first creates a copy of the new content. It then removes all children nodes of this node. Finally, it adds the new content as children nodes. This means that you can replace children nodes using a query on the children nodes themselves.
## Examples
The following example creates an XML tree that contains children nodes. It then replaces all of the children nodes with a single element.
To see an example of replacing the children nodes with the results of a [!INCLUDE[vbteclinq](~/includes/vbteclinq-md.md)] query, see <xref:System.Xml.Linq.XContainer.ReplaceNodes%2A>.
```csharp
XElement root = new XElement("Root",
new XElement("Child", 1),
new XElement("Child", 2),
new XElement("Child", 3),
new XElement("Child", 4),
new XElement("Child", 5)
);
root.ReplaceNodes(
from el in root.Elements()
where (int)el >= 3
select el
);
Console.WriteLine(root);
```
```vb
Dim root As XElement = _
<Root>
<Child>1</Child>
<Child>2</Child>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
root.ReplaceNodes( _
From el In root.Elements _
Where el.Value >= 3 _
Select el)
Console.WriteLine(root)
```
This example produces the following output:
```xml
<Root>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
<Member MemberName="ReplaceNodes">
<MemberSignature Language="C#" Value="public void ReplaceNodes (params object[] content);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void ReplaceNodes(object[] content) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Xml.Linq.XContainer.ReplaceNodes(System.Object[])" />
<MemberSignature Language="VB.NET" Value="Public Sub ReplaceNodes (ParamArray content As Object())" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void ReplaceNodes(... cli::array &lt;System::Object ^&gt; ^ content);" />
<MemberSignature Language="F#" Value="member this.ReplaceNodes : obj[] -&gt; unit" Usage="xContainer.ReplaceNodes content" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xml.XDocument</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Xml.Linq</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="content" Type="System.Object[]">
<Attributes>
<Attribute FrameworkAlternate="dotnet-uwp-10.0">
<AttributeName>System.ParamArray</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="content">A parameter list of content objects.</param>
<summary>Replaces the children nodes of this document or element with the specified content.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
For details about the valid content that can be passed to this function, see [Valid Content of XElement and XDocument Objects](https://msdn.microsoft.com/library/aee2d319-5c5f-4b99-9bb4-2f58232577ae).
This method will raise the <xref:System.Xml.Linq.XObject.Changed> and the <xref:System.Xml.Linq.XObject.Changing> events.
This method has snapshot semantics. It first creates a copy of the new content. It then removes all children nodes of this node. Finally, it adds the new content as children nodes. This means that you can replace children nodes using a query on the children nodes themselves.
## Examples
The following example creates a dictionary and an XML tree. It then queries the dictionary, projects the results to an <xref:System.Collections.Generic.IEnumerable%601> of <xref:System.Xml.Linq.XElement>, and replaces the contents of the XML tree with the results of the query.
```csharp
XElement root = new XElement("Root",
new XElement("Child", 1),
new XElement("Child", 2),
new XElement("Child", 3),
new XElement("Child", 4),
new XElement("Child", 5)
);
root.ReplaceNodes(
from el in root.Elements()
where (int)el >= 3
select el
);
Console.WriteLine(root);
```
```vb
Dim root As XElement = _
<Root>
<Child>1</Child>
<Child>2</Child>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
root.ReplaceNodes( _
From el In root.Elements _
Where el.Value >= 3 _
Select el)
Console.WriteLine(root)
```
This example produces the following output:
```xml
<Root>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
```
]]></format>
</remarks>
<altmember cref="Overload:System.Xml.Linq.XContainer.Add" />
<altmember cref="M:System.Xml.Linq.XContainer.RemoveNodes" />
<related type="Article" href="https://msdn.microsoft.com/library/f0fe21e9-ee43-4a55-b91a-0800e5782c13">LINQ to XML</related>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.