Extensions.Remove Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
|
Remove(IEnumerable |
Removes every attribute in the source collection from its parent element. |
|
Remove |
Removes every node in the source collection from its parent node. |
Remove(IEnumerable)
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
Removes every attribute in the source collection from its parent element.
public:
[System::Runtime::CompilerServices::Extension]
static void Remove(System::Collections::Generic::IEnumerable ^ source);
public static void Remove(this System.Collections.Generic.IEnumerable source);
public static void Remove(this System.Collections.Generic.IEnumerable source);
static member Remove : seq -> unit
Public Sub Remove (source As IEnumerable(Of XAttribute))
Parameters
- source
- IEnumerable<XAttribute>
An IEnumerable
Examples
The following example retrieves a collection of attributes, and then calls this method to remove them from their parent elements.
XElement root = new XElement("Root",
new XAttribute("Att1", 1),
new XAttribute("Att2", 2),
new XAttribute("Att3", 3),
new XAttribute("Att4", 4),
new XAttribute("Att5", 5)
);
IEnumerable atList =
from at in root.Attributes()
where (int)at >= 3
select at;
atList.Remove();
Console.WriteLine(root);
Dim root As XElement =
Dim atList = From at In root.Attributes _
Where at.Value >= 3 _
Select at
atList.Remove()
Console.WriteLine(root)
This example produces the following output:
Remarks
This method uses snapshot semantics - that is, it copies the attributes in the source collection to a System.Collections.Generic.List
See also
- RemoveAttributes()
- Attributes
- System.Xml.Linq.XAttribute.Remove
- System.Xml.Linq.XNode.Remove
- LINQ to XML overview
Applies to
Remove(IEnumerable)
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
- Source:
- Extensions.cs
Removes every node in the source collection from its parent node.
public:
generic
where T : System::Xml::Linq::XNode[System::Runtime::CompilerServices::Extension]
static void Remove(System::Collections::Generic::IEnumerable ^ source);
public static void Remove(this System.Collections.Generic.IEnumerable source) where T : System.Xml.Linq.XNode;
public static void Remove(this System.Collections.Generic.IEnumerable source) where T : System.Xml.Linq.XNode;
static member Remove : seq<'T (requires 'T :> System.Xml.Linq.XNode)> -> unit (requires 'T :> System.Xml.Linq.XNode)
Public Sub Remove(Of T As XNode) (source As IEnumerable(Of T))
Type Parameters
- T
The type of the objects in source, constrained to XNode.
Parameters
- source
-
IEnumerable
An IEnumerable
Examples
The following example retrieves a collection of elements. It then calls this method to remove the elements from their parent element.
XElement root = new XElement("Root",
new XElement("Data", 1),
new XElement("Data", 2),
new XElement("Data", 3),
new XElement("Data", 4),
new XElement("Data", 5)
);
IEnumerable elList =
from el in root.Elements()
where (int)el >= 3
select el;
elList.Remove();
Console.WriteLine(root);
Dim root As XElement = _
1
2
3
4
5
Dim elList = From el In root.Elements _
Where el.Value >= 3 _
Select el
elList.Remove()
Console.WriteLine(root)
This example produces the following output:
1
2
Remarks
This method uses snapshot semantics - that is, it copies the attributes in the source collection to a List before disconnecting them from their parents. This is required to avoid issues with mixed imperative/declarative code. For more information, see Mixed Declarative Code/Imperative Code Bugs (LINQ to XML).
See also
- RemoveAll()
- Attributes
- System.Xml.Linq.XAttribute.Remove
- System.Xml.Linq.XNode.Remove
- LINQ to XML overview