How to force XDocument to output the prolog in uppercase while preserving identation and formatting?

前端 未结 4 1853
刺人心
刺人心 2021-01-23 05:34

I want XDocument to output the XML prolog (for example \"\") in uppercase.

Here is how I\'m cur

4条回答
  •  粉色の甜心
    2021-01-23 06:11

    I had the same problem, the program that should read the XML could not handle the "utf" in lower case.

    Found this simple workaround:

        XmlWriterSettings settings = new XmlWriterSettings();
    
        settings.Indent = true;
        settings.OmitXmlDeclaration = true;
        settings.NewLineHandling = NewLineHandling.Replace;
        settings.NewLineOnAttributes = true;       
    
                    using (
                        XmlWriter xmlWriter =
                            XmlWriter.Create(
                                Application.StartupPath + @"\Output\products.xml", settings))
                    {
    
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteRaw("\r\n");
                        xmlWriter.WriteStartElement("products");
    

    etc....

提交回复
热议问题