System.Xml.Linq.XElement RootElement = xDoc.Element("SYSTEM_CONFIG")
System.Xml.Linq.XElement element = new System.Xml.Linq.XElement("ODBCconfig")
System.Xml.Linq.XAttribute attribute = new System.Xml.Linq.XAttribute("DataSourceName", "testSybase")
element.Add(attribute)
attribute = new System.Xml.Linq.XAttribute("Description", "")
element.Add(attribute)
attribute = new System.Xml.Linq.XAttribute("SeverName", "LT")
element.Add(attribute)
attribute = new System.Xml.Linq.XAttribute("SeverPort", "5000")
element.Add(attribute)
RootElement.Add(element)
xDoc.Save(Server.MapPath("XMLFile1.xml"))
这样看看
private void button1_Click(object sender, EventArgs e){
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)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)