• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
要想人前显贵,必定人后受罪。
博客园    首页    新随笔    联系   管理    订阅  订阅
C#操作Xml文件(删除)

步骤如下:

1、导入命名空间 system.Xml。

2、创建Xml文档。

3、加载要读取的xml文件。

4、SelectSingleNode()进行选中节点。

例子练习。

static void Main(string[] args)
{            
    //创建Xml文件。
    XmlDocument xml = new XmlDocument();
    //加载xml文件。
    xml.Load("Items.xml");
    //拿到要操作的节点。
    XmlNode nodeList = xml.SelectSingleNode("/Items/Item");
    //移除。
    nodeList.RemoveAll();
    Console.WriteLine("移除成功!");
    Console.ReadKey();
}

End。

 

posted on 2017-09-25 13:37  行走的蜗牛哦  阅读(1796)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3