Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Similar to my own question about removing commentsmy own question about removing comments you can do this:

// load your Xml string into an XDocument var xml = XDocument.Parse(yourxmlstringhere); foreach (var node in xml.SelectNodes("//orderby").ToList()) { node.ParentNode.RemoveChild(node); } 

Which will find all orderbyelements, navigate to their parent element and delete them from there.

I adopted this answer from AnthonyAnthony, who pointed out that it will be safer to create a List before removing.

Similar to my own question about removing comments you can do this:

// load your Xml string into an XDocument var xml = XDocument.Parse(yourxmlstringhere); foreach (var node in xml.SelectNodes("//orderby").ToList()) { node.ParentNode.RemoveChild(node); } 

Which will find all orderbyelements, navigate to their parent element and delete them from there.

I adopted this answer from Anthony, who pointed out that it will be safer to create a List before removing.

Similar to my own question about removing comments you can do this:

// load your Xml string into an XDocument var xml = XDocument.Parse(yourxmlstringhere); foreach (var node in xml.SelectNodes("//orderby").ToList()) { node.ParentNode.RemoveChild(node); } 

Which will find all orderbyelements, navigate to their parent element and delete them from there.

I adopted this answer from Anthony, who pointed out that it will be safer to create a List before removing.

Source Link
Filburt
  • 18.1k
  • 14
  • 106
  • 167

Similar to my own question about removing comments you can do this:

// load your Xml string into an XDocument var xml = XDocument.Parse(yourxmlstringhere); foreach (var node in xml.SelectNodes("//orderby").ToList()) { node.ParentNode.RemoveChild(node); } 

Which will find all orderbyelements, navigate to their parent element and delete them from there.

I adopted this answer from Anthony, who pointed out that it will be safer to create a List before removing.