Error: The XML declaration must be the first node in the document

前端 未结 4 1158
有刺的猬
有刺的猬 2021-01-11 23:02

I am getting \"Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it\" error

4条回答
  •  鱼传尺愫
    2021-01-11 23:44

    I'm using the following function to remove whitespace from xml:

    public static void DoRemovespace(string strFile)
        {
            string str = System.IO.File.ReadAllText(strFile);
            str = str.Replace("\n", "");
            str = str.Replace("\r", "");
            Regex regex = new Regex(@">\s*<");
            string cleanedXml = regex.Replace(str, "><");
            System.IO.File.WriteAllText(strFile, cleanedXml);
    
        }
    

提交回复
热议问题