开发者

regex removing specified empty xml tag using C#

开发者 https://www.devze.com 2022-12-29 11:03 出处:网络
I would like to re开发者_如何学运维move tag like the following one with its attributes using C# .Net

I would like to re开发者_如何学运维move tag like the following one with its attributes using C# .Net how can i do it?

<aaa type="1" class="2" />

other tags like <bbb type="5" class="4" /> i would like to keep.

Best Regards,


I'd advise against regular expressions for this task.

However you can use LINQ to XML to remove tags with name "aaa" like this:

XDocument doc = XDocument.Load("input.xml");
doc.Descendants("aaa").Remove();
doc.Save("output.xml");
0

精彩评论

暂无评论...
验证码 换一张
取 消