我从第三方应用程序中提取xml文件,看起来像这样
<round round_id="14208" name="5th Round" start_date="2013-09-06" end_date="2013-09-10" type="cup" groups="0" has_outgroup_matches="no" last_updated="2011-04-05 14:15:02">
--Some Data with more elements
</round>
<round round_id="14208" name="5th Round" start_date="2013-09-06" end_date="2013-09-10" type="cup" groups="0" has_outgroup_matches="no" last_updated="2011-04-05 14:15:02">
--Some Data with more elements
</round>
我的问题是有时候这个标签带有像这样的自闭标签
<round round_id="14208" name="5th Round" start_date="2013-09-06" end_date="2013-09-10" type="cup" groups="0" has_outgroup_matches="no" last_updated="2011-04-05 14:15:02"/>
我想检查自闭标签并删除元素。
请帮帮我。 感谢
答案 0 :(得分:2)
var file = "C:\\YourPath\\data.xml";
var doc = new XmlDocument();
doc.Load(file);
var nodes = doc.SelectNodes("/rounds/round");
foreach (XmlNode item in nodes)
{
if (item.InnerXml == String.Empty)
{
item.ParentNode.RemoveChild(item);
}
}
doc.Save(file);