C#修改xml节点的名称

zhanshang2606 2014-04-16 05:34:58
xml结构:
<?xml version="1.0" encoding="ISO-8859-1"?>
<cfgfile:cmconfigdatafile xmlns:RAN="http://www.huawei.com/specs/huawei_cme_GERAN_NRM_baseline_all" xmlns:cfgfile="http://www.huawei.com/specs/huawei_cme_RAN6.0_BulkCM_FileFormat_baseline_1.0.0" xmlns:gn="http://www.huawei.com/specs/huawei_CME_GenericNRMdescription_baseline_1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.huawei.com/specs/huawei_cme_GERAN_NRM_baseline_all CMEWRAN_NRM_Spec_ALL.xsd http://www.huawei.com/specs/huawei_cme_RAN6.0_BulkCM_FileFormat_baseline_1.0.0 CMEWRANcfgCMData_spec.xsd http://www.huawei.com/specs/huawei_CME_GenericNRMdescription_baseline_1.0.0 CMEWRANGenericNRM.xsd">
<cfgfile:fileheader filetype="ExportFile" />
<cfgfile:subnetwork subnetname="ha3ghua01">
<cfgfile:subsession neid="10.144.175.124" netype="BSC6900UMTSNE" neversion="V900R013C00" opmode="BreakonFailure">
<gn:DataContainer>
<RAN:RAN>
<Radio>
<ULAC>
<attributes>
<CNOPINDEX>0</CNOPINDEX>
<LAC>1025</LAC>
<PLMNVALTAGMIN>222</PLMNVALTAGMIN>
<PLMNVALTAGMAX>223</PLMNVALTAGMAX>
</attributes>
<USAC>
<attributes>
<SAC>4120</SAC>
<CNOPINDEX>0</CNOPINDEX>
<LAC>1025</LAC>
</attributes>
</USAC>
</ULAC>
</Radio>
</RAN:RAN>
</gn:DataContainer>
</cfgfile:subsession>
</cfgfile:subnetwork>
<cfgfile:filefooter datetime="2014-04-03T14:05:30" />
</cfgfile:cmconfigdatafile>
C#怎样将节点<ULAC>改成<moi xsi:type="ULAC">,<USAC>改成<moi xsi:type="USAC">
...全文
329 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
修改下 是

private static void UpdateXml(string path)
        {
            if (File.Exists(path))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                XmlNode ulac = doc.DocumentElement.SelectSingleNode("//ULAC");
                if (ulac != null)
                {
                    XmlNode newNode = doc.CreateElement("moi");
                    XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
                    attr.Value = "ULAC";
                    newNode.Attributes.Append(attr);
                    newNode.InnerXml = ulac.InnerXml;
                    ulac.ParentNode.ReplaceChild(newNode, ulac);
                }
                XmlNode usac = doc.DocumentElement.SelectSingleNode("//USAC");
                if (usac != null)
                {
                    XmlNode newNode = doc.CreateElement("moi");
                    XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
                    attr.Value = "USAC";
                    newNode.Attributes.Append(attr);
                    newNode.InnerXml = usac.InnerXml;
                    usac.ParentNode.ReplaceChild(newNode, usac);
                }
                doc.Save(path);
            }
        }
  • 打赏
  • 举报
回复

private static void UpdateXml(string path)
        {
            if (File.Exists(path))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("test.xml");
                XmlNode ulac = doc.DocumentElement.SelectSingleNode("//ULAC");
                if (ulac != null)
                {
                    XmlNode newNode = doc.CreateElement("moi");
                    XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
                    attr.Value = "ULAC";
                    newNode.Attributes.Append(attr);
                    newNode.InnerXml = ulac.InnerXml;
                    ulac.ParentNode.ReplaceChild(newNode, ulac);
                }
                XmlNode usac = doc.DocumentElement.SelectSingleNode("//USAC");
                if (usac != null)
                {
                    XmlNode newNode = doc.CreateElement("moi");
                    XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
                    attr.Value = "USAC";
                    newNode.Attributes.Append(attr);
                    newNode.InnerXml = usac.InnerXml;
                    usac.ParentNode.ReplaceChild(newNode, usac);
                }
                doc.Save(path);
            }
        }
zhanshang2606 2014-04-16
  • 打赏
  • 举报
回复
还有 </USAC>和</USAC>改成</moi>

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧