<?xml version="1.0" encoding="UTF-8"?>
<cmconfigdatafile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.huawei.com/specs/SRAN" xsi:schemaLocation="http://www.huawei.com/specs/SRAN CMELTE_NRM_Spec_V1R8C00.xsd">
<fileheader filetype="ExportFile"/>
<subsession>
<NE xsi:type="SRAN" netype="LTE" neversion="BTS3900 V100R008C00" neid="LTE_0001">
<module xsi:type="LTESiteModule">
<moi xsi:type="ANR"><attributes><ACTIVEPCICONFLICTSWITCH>0</ACTIVEPCICONFLICTSWITCH><ADDCELLTHD>80</ADDCELLTHD><DELCELLTHD>0</DELCELLTHD><FASTANRCDMA1XRTTPILOTTHD>-30</FASTANRCDMA1XRTTPILOTTHD><FASTANRCDMAHRPDPILOTTHD>-16</FASTANRCDMAHRPDPILOTTHD><FASTANRCHECKPERIOD>60</FASTANRCHECKPERIOD><FASTANRINTERRATMEASUENUM>5</FASTANRINTERRATMEASUENUM><FASTANRINTERRATUENUMTHD>20</FASTANRINTERRATUENUMTHD><FASTANRINTRARATMEASUENUM>5</FASTANRINTRARATMEASUENUM><FASTANRINTRARATUENUMTHD>20</FASTANRINTRARATUENUMTHD><FASTANRMODE>0</FASTANRMODE><FASTANRRPRTAMOUNT>2</FASTANRRPRTAMOUNT><FASTANRRPRTINTERVAL>6</FASTANRRPRTINTERVAL><FASTANRRSCPTHD>-106</FASTANRRSCPTHD><FASTANRRSRPTHD>-102</FASTANRRSRPTHD><FASTANRRSSITHD>-103</FASTANRRSSITHD><NCELLHOSTATNUM>200</NCELLHOSTATNUM><OPTMODE>0</OPTMODE><STARTTIME>14:00:00</STARTTIME><STATISTICNUMFORNRTDEL>200</STATISTICNUMFORNRTDEL><STATISTICPERIOD>1440</STATISTICPERIOD><STATISTICPERIODFORNRTDEL>10080</STATISTICPERIODFORNRTDEL><STOPTIME>15:00:00</STOPTIME></attributes></moi>
<moi xsi:type="APPCERT"><attributes><APPCERT>appcert.pem</APPCERT><APPTYPE>0</APPTYPE></attributes></moi>
<moi xsi:type="APPCERT"><attributes><APPCERT>appcert.pem</APPCERT><APPTYPE>1</APPTYPE></attributes></moi>
<moi xsi:type="ALGODEFAULTPARA"><attributes><DEFDOPPLERLEVEL>1</DEFDOPPLERLEVEL></attributes></moi>
</module>
</NE>
</subsession>
<filefooter datetime="2014-03-13 07:45:16"/>
</cmconfigdatafile>
我想将节点<moi xsi:type="APPCERT">整个删除掉,用代码怎么实现
7 个解决方案
#1
string filepath = "" ; // Your file path
XmlDocument doc = new XmlDocument();
doc.Load(filepath);
XmlNode xn = doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];
List<XmlNode> lx=new List<XmlNode>();
for (int i = 0; i < xn.ChildNodes.Count; i++)
{
lx.Add(xn.ChildNodes[i]);
}
foreach (var item in lx)
{
if (item.Name=="moi"&&item.Attributes["xsi:type"].Value=="APPCERT")
{
xn.RemoveChild(item);
}
}
doc.Save(filepath);
#2
我还说你那个怎么结贴了,原来又发了一个。之前没在额。
我这个比楼上那位稍微简洁了一点儿
我这个比楼上那位稍微简洁了一点儿
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
XmlNode key = xml.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];//<module xsi:type="LTESiteModule">
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
xml.Save(xmlpath);
#3
#4
如果有多个<subsession></subsession>,代码怎么写呢
#5
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
{
XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
}
xml.Save(xmlpath);
#6
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
{
XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
}
xml.Save(xmlpath);
#7
#1
string filepath = "" ; // Your file path
XmlDocument doc = new XmlDocument();
doc.Load(filepath);
XmlNode xn = doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];
List<XmlNode> lx=new List<XmlNode>();
for (int i = 0; i < xn.ChildNodes.Count; i++)
{
lx.Add(xn.ChildNodes[i]);
}
foreach (var item in lx)
{
if (item.Name=="moi"&&item.Attributes["xsi:type"].Value=="APPCERT")
{
xn.RemoveChild(item);
}
}
doc.Save(filepath);
#2
我还说你那个怎么结贴了,原来又发了一个。之前没在额。
我这个比楼上那位稍微简洁了一点儿
我这个比楼上那位稍微简洁了一点儿
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
XmlNode key = xml.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];//<module xsi:type="LTESiteModule">
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
xml.Save(xmlpath);
#3
#4
如果有多个<subsession></subsession>,代码怎么写呢
#5
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
{
XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
}
xml.Save(xmlpath);
#6
string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
XmlDocument xml = new XmlDocument();
xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
{
XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
XmlNodeList nodes = key.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
XmlElement node = (XmlElement)nodes[i];
if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
{
key.RemoveChild(node);
i -= 1;
}
}
}
xml.Save(xmlpath);