众所周知~XmlWriter类 与 DOM 的区别,前者是用流写入器写入内容,资源消耗很少。可问题是,我从书上看来,.net对XmlWriter有个支持类XmlTextWriter,该类在写入文件的时候,是重新写的,也就是说,如果我想在原有的xml文档后面接着写入内容,恐怕不行~~ 是不是这样呢?如果是这样的话,有没有什么解决方案呢?
xml is normally in the text format, if it is a normal text file, you could append contents to the end of the file, but since xml has a start tag and end tag, so you need to INSERT your content before the end tag, that is not possible for text format (if you want to keep the integrity of the xml format)
XmlTextWriter temp = new XmlTextWriter(tempstream,System.Text.Encoding.UTF8);
tempstream.Position = 5; temp.WriteStartElement("ss","s1","s11");
temp.WriteString("sss");
temp.WriteEndElement(); temp.Flush();
byte[] tempbyte = new byte[6];
string temps = "</xxx>";
for(int i=0;i<6;i++)
{
tempbyte[i] = Convert.ToByte(temps[i]);
}
tempstream.Write(tempbyte,0,6);其中xml开始为
<xxx></xxx>写后为<xxx><ss:s1 xmlns:ss="s11">sss</ss:s1></xxx>