A
A
anonymous2017-09-03 13:12:37
.NET
anonymous, 2017-09-03 13:12:37

Why doesn't it remove the xml element (LINQ to XML)?

What am I doing wrong?
For some reason it does not remove the element from XML

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<links>
  <link>http://24tv.ua/rss/all.xml</link>
  <link>http://www.pravda.com.ua/rss/view_mainnews/</link>
</links>

myOwner.xmlDoc.Descendants("links")
                    .Elements("link")
                    .Where(x => x.Value == listBoxLinks.SelectedItem)
                    .Remove();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-09-04
@anonymouss

This will not work, you cannot change the collection when it is enumerated.

foreach(var n in myOwner.xmlDoc.Descendants("links")
                    .Elements("link")
                    .Where(x => x.Value == listBoxLinks.SelectedItem)
                   .ToList())
{
                   n.Remove();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question