Delete XML Element using LINQ to query parent

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have been adding XML Elements using LINQ by locating the parent node and then inserting the desired XML element.  I now need to delete an XML Element.  I was assuming that I could use the same logic but use the Remove() method.  However I am getting an error on <br/> <br/> Error    59    Too many arguments to Public Sub Remove()<br/> <br/> on the line: parentNode.Remove(oldElement)<br/> <br/> Is this because I can only add to a parent node and not delete from a parent node?<br/> <br/> Dim doc As XElement = XElement.Load(FullTempXMLPathAndName)<br/> Dim oldElement As XElement<br/> Dim parentNode As XElement<br/> delete from XML File<br/> oldElement = _<br/>             <Keyword Name=<%= Item %>><br/>             </Keyword><br/>             <br/> Dim parentQuery = From r As XElement In doc...<ActualKeyWords><br/> parentNode = parentQuery.FirstOrDefault<br/> If (parentNode IsNot Nothing) Then<br/> Delete Code Snippet from XML<br/> parentNode.Remove(oldElement)<br/> End If<br/> doc.Save(FullTempXMLPathAndName)

View the full article
 
Back
Top