Reputation: 27757
How do I take this XML and filter out the menu element that is marked as expert using XLINQ and return the rest?
<data>
<preferences />
<menus>
<menu type="expert">
<sub />
</menu>
<menu type="beginner">
<sub />
</menu>
</menus>
</data>
So the result would be:
<data>
<preferences />
<menus>
<menu type="beginner">
<sub />
</menu>
</menus>
</data>
Upvotes: 1
Views: 109
Reputation: 1063864
// parse the DOM if needed
XDocument doc =XDocument.Parse(xml);
// find the expert menu items
var remove = doc.Descendants("menu").Where(
menu => (string)menu.Attribute("type") == "expert").ToList();
// remove them
foreach (var item in remove) {
item.Remove();
}
// to get output
string s = doc.ToString();
Upvotes: 2