
{
string File = @"c:\TableColumns.xml"
System.Xml.XmlDocument xmlDoc=new System.Xml.XmlDocument()
xmlDoc.Load(File)
System.Xml.XmlNode xn = xmlDoc.DocumentElement.SelectSingleNode("TableColumns/TableColumn[@id=\"IndexUnit\"]")//读取id=IndexUnit的TableColumn节点,在xml教材中的xPath章节专门介绍这种查询方法。
System.Xml.XmlElement vs=xmlDoc.CreateElement("Visibility")//创建新节点
System.Xml.XmlElement Hd = xmlDoc.CreateElement("Hidden")
Hd.InnerText = "true"
vs.AppendChild(Hd)//添加为子节点
xn.AppendChild(vs)
xmlDoc.Save(File)
}
public void InsertXml(){
string path="Xml文件的位置"
XmlDocument doc=new XmlDocument()
doc.Load(path)
XmlNode root=doc.DocumentElement//获得根节点
foreach(XmlNode items in root.ChildNodes)
{
if(items.Name=="data")
{
foreach(XmlNode item in items.ChildNodes)
{
if(item.Name="meter")
{
XmlNode xm1=doc.CreateElement("function")
function.SetAttribute("id","06")
function.SetAttribute("coding","A")
function.SetAttribute("error","A")
function.InnerText="223.33"
item.AppendChild(function)
doc.Save(path)
return
}
}
}
}
}
参考下吧
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)