您当前的位置: 首页 >  c#

衣舞晨风

暂无认证

  • 0浏览

    0关注

    1156博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C# 通过传入节点name及节点value,来删除XML相应节点

衣舞晨风 发布时间:2014-01-08 09:46:39 ,浏览量:0

//通过传入节点name及节点value,来删除相应节点
public static string OperateXml(string keyInfo, string valueInfo)
{
    if (File.Exists(filePath))
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(filePath);
        XmlNode xnRoot = xmlDoc.SelectSingleNode("根节点");
        if (xnRoot == null)
        {
            xnRoot = xmlDoc.CreateNode(XmlNodeType.Element, "根节点", "");
            xmlDoc.AppendChild(xnRoot);
        }                       
        XmlNodeList xnl = xmlDoc.SelectSingleNode("根节点").ChildNodes;
        for (int i = 0; i < xnl.Count; i++)
        {
            XmlElement xe = (XmlElement)xnl.Item(i);
            if (xe.Name.Equals(keyInfo))
            {
                xnRoot.RemoveChild(xe);
                if (i < xnl.Count) i = i - 1;
            }
        }
        xmlDoc.Save(filePath);
        return null;
}
关注
打赏
1647422595
查看更多评论
立即登录/注册

微信扫码登录

0.0388s