2010-05-09 18 views
-1

我想使用C#.Net 去除如下標記,並使用它的屬性我該怎麼做?正則表達式使用C#去除指定的空xml標記

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

其他標籤如<bbb type="5" class="4" />我想保留。

最好的問候,

+0

從什麼刪除呢?你如何獲得XML文檔?向我們展示一些代碼,以便我們弄清楚你在說什麼。 – Oded 2010-05-09 08:28:41

+0

你不能,不健壯。 XML不是常規語言,不能用正則表達式可靠地解析。 http://stackoverflow.com/questions/1875258/regular-expression-to-parse-links-from-html-code/1875281#1875281 – 2010-05-09 08:29:47

+0

用空的替換字符串 – John 2010-05-09 08:29:48

回答

2

我建議這個任務的正則表達式。

但是你可以使用LINQ到XML刪除名稱爲「AAA」標籤是這樣的:

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