Extensions.Remove Method (System.Xml.Linq) (original) (raw)
Source:
Source:
Source:
Source:
Removes every node in the source collection from its parent node.
public:
generic <typename T>
where T : System::Xml::Linq::XNode[System::Runtime::CompilerServices::Extension]
static void Remove(System::Collections::Generic::IEnumerable<T> ^ source);public static void Remove<T>(this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XNode;public static void Remove<T>(this System.Collections.Generic.IEnumerable<T?> 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)<Extension()>
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
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<XElement> elList =
from el in root.Elements()
where (int)el >= 3
select el;
elList.Remove();
Console.WriteLine(root);
Dim root As XElement = _
<Root>
<Data>1</Data>
<Data>2</Data>
<Data>3</Data>
<Data>4</Data>
<Data>5</Data>
</Root>
Dim elList = From el In root.Elements _
Where el.Value >= 3 _
Select el
elList.Remove()
Console.WriteLine(root)
This example produces the following output:
<Root>
<Data>1</Data>
<Data>2</Data>
</Root>
Remarks
This method uses snapshot semantics - that is, it copies the attributes in the source collection to a List<T> 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).