Xml节点交换

简介:

public static bool XmlExChange(int oldnum, int newnum)
{
bool res = true;
try
{
string path = Config.PlayMusicListPath;
if (File.Exists(path))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);

XmlNodeList nodeList = xmlDoc.SelectSingleNode("musiclist").ChildNodes;
if (nodeList[oldnum].Name == "music" && nodeList[newnum].Name == "music")
{
XmlNode oldxn = nodeList[oldnum];
XmlNode newxn = nodeList[newnum];

XmlNode parent=oldxn.ParentNode;
XmlNode t1=oldxn.NextSibling;
XmlNode t2=newxn.NextSibling;
if(t1!=null)
parent.InsertBefore(newxn,t1);
else
parent.AppendChild(newxn);
if (t2 != null)
parent.InsertBefore(oldxn,t2);
else
parent.AppendChild(oldxn);
xmlDoc.Save(path);

}
}
}
catch
{
res = false;
}
return res;
}




本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/09/09/1563322.html,如需转载请自行联系原作者


相关文章
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
XML 分布式计算 资源调度
大数据-02-Hadoop集群 XML配置 超详细 core-site.xml hdfs-site.xml 3节点云服务器 2C4G HDFS Yarn MapRedece(一)
大数据-02-Hadoop集群 XML配置 超详细 core-site.xml hdfs-site.xml 3节点云服务器 2C4G HDFS Yarn MapRedece(一)
779 5
|
XML 资源调度 网络协议
大数据-02-Hadoop集群 XML配置 超详细 core-site.xml hdfs-site.xml 3节点云服务器 2C4G HDFS Yarn MapRedece(二)
大数据-02-Hadoop集群 XML配置 超详细 core-site.xml hdfs-site.xml 3节点云服务器 2C4G HDFS Yarn MapRedece(二)
839 5
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
分布式计算 资源调度 Hadoop
大数据-01-基础环境搭建 超详细 Hadoop Java 环境变量 3节点云服务器 2C4G XML 集群配置 HDFS Yarn MapRedece
大数据-01-基础环境搭建 超详细 Hadoop Java 环境变量 3节点云服务器 2C4G XML 集群配置 HDFS Yarn MapRedece
598 4
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树
|
XML JavaScript 数据格式
XML DOM 遍历节点树
XML DOM 遍历节点树

热门文章

最新文章

相关课程

更多