I am looking for a good approach that can remove empty tags from XML efficiently. What do you recommend? Regex? XDocument? XmlTextReader?
For example,
XDocument
is probably simplest to implement, and will give adequate performance if you know your documents are reasonably small.
XmlTextReader
will be faster and use less memory than XDocument when processing very large documents.
Regex is best for handling text rather than XML. It might not handle all edge cases as you would like (e.g. a tag within a CDATA section; a tag with an xmlns attribute), so is probably not a good idea for a general implementation, but may be adequate depending on how much control you have of the input XML.