Help me,please!!!!
sceh 2004-10-15 04:59:03 一般删除xml文档中某个节点的代码:
public class Delete //删除节点
{
public bool delete(string FileName,string NodeName)
{
try
{
XmlDocument xmldoc=new XmlDocument();
xmldoc.Load(FileName); //读取文件
XmlNodeList xnl=xmldoc.SelectSingleNode("根节点名").ChildNodes;
foreach(XmlNode xn in xnl) //遍历所有节点
{
XmlElement xe=(XmlElement)xn;
if(xe.Name==NodeName) //如果找到节点
{
xe.ParentNode.RemoveChild(xe); //删除改节点
}
}
xmldoc.Save(FileName);
return true;
}
catch
{
return false;
}
}
}
能否在保证参数个数不变的情况下,改写成代码里不出现根节点名?并且参数NodeName有可能是文件里的N层节点。
是不是要用到xmldoc.DocumentElement.SelectNodes呢?