日期:2014-05-17  浏览次数:20828 次

请问一个在C#里生成xml文档,一定要有root吗?
一旦我把 writer.WriteStartElement(root);注释掉  就会报错啊
   XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = ("    ");
            settings.CloseOutput = true;
            settings.OmitXmlDeclaration = true;
            using (XmlWriter writer = XmlWriter.Create(output, settings))
            {
              //  writer.WriteStartElement(root);
                writer.WriteStartDocument();
                ArrayList arrText = new ArrayList();
                StreamReader objReader = new StreamReader(pathtext);
                while (!objReader.EndOfStream)
                {
                    String sLine = objReader.ReadLine();
                    int start = sLine.IndexOf('(');
                    int end = sLine.IndexOf(')');
                    string temp = sLine.Substring(start + 1, end - start - 1);
                    string[] s = temp.Split(',');
                    string temp1 = null;
                    for (int i = 0; i < s.Length; i++)
                    {
                        if (s[i].Contains("'"))
                        {
                            temp1 = s[i].Substring(1, s[i].Length - 2);