如何使用 XMLWriter 类追加 XML 文件
XmlWriterSettings xmlFragments = new XmlWriterSettings();
xmlFragments.Indent = true ;
XmlTextWriter xWriter = new XmlTextWriter(_logFilePath, null);
xWriter.WriteStartDocument();//starting document
xWriter.WriteStartElement("values");//starting parent node
xWriter.WriteStartElement("values1");//1st child node
xWriter.WriteAttributeString("id", "200");//attributes of child node
xWriter.WriteAttributeString("name", "ABCD");
xWriter.WriteString("ISO Company");//innertext
xWriter.WriteEndElement();
xWriter.WriteStartElement("num");//2nd child node
xWriter.WriteAttributeString("more", "500");
xWriter.WriteAttributeString("less", "101");
xWriter.WriteString("numeric");
xWriter.WriteEndElement();
xWriter.WriteStartElement("r", "runnnig", "");//3rd child node
xWriter.WriteAttributeString("fast", "500km");
xWriter.WriteAttributeString("slow", "10km");
xWriter.WriteString("killometers");
xWriter.WriteEndElement();
xWriter.WriteStartElement("character");
xWriter.WriteAttributeString("char", "a");
xWriter.WriteAttributeString("another", "b");
xWriter.WriteEndElement();
xWriter.WriteEndElement();
xWriter.WriteEndDocument();
xWriter.Close();
我正在尝试在 xmlwriter 中加载 xml 文件,但是这个类会覆盖以前的标签,但我不想覆盖标签。