📄 xml文件insert.txt
字号:
using System.Data;
using System.Xml;
using System.IO;
private XmlDocument doc;
//插入节点
doc.Load("books.xml");
XmlElement newBook=doc.CreateElement("book");
newBook.SetAttribute("genre","Mystery");
newBook.SetAttribute("publicationdate","2001");
newBook.SetAttribute("ISBN","123456789");
//
XmlElement newTitle=doc.CreateElement("title");
newTitle.InnerText="Case of the Missing Cookie";
newBook.AppendChild(newTitle);
//
XmlElement newAuthor=doc.CreateElement("author");
newBook.AppendChild(newAuthor);
//
XmlElement newName=doc.CreateElement("name");
newName.InnerText="C.Monster";
newAuthor.AppendChild(newName);
//
XmlElement newPrice=doc.CreateElement("price");
newPrice.InnerText="9.95";
newBook.AppendChild(newPrice);
//
doc.DocumentElement.AppendChild(newBook);
//
XmlTextWriter tr=new XmlTextWriter("booksedit.xml",null);
tr.Formatting=Formatting.Indented;
doc.WriteContentTo(tr);
tr.Close();
XmlNodeList nodeLst=doc.GetElementsByTagName("title");
foreach(XmlNode node in nodeLst)
listBox1.Items.Add(node.InnerText);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -