public string FormatXml(TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
        {
            XmlDocument doc;

            try {
                doc = new XmlDocument();
                doc.LoadXml(input);
            } catch {
                // Ignore malformed xml
                return(input);
            }

            StringWriter       sw        = new StringWriter();
            XmlFormatterWriter xmlWriter = new XmlFormatterWriter(sw);

            xmlWriter.WriteNode(doc, formattingPolicy, textPolicy);
            xmlWriter.Flush();
            return(sw.ToString());
        }
示例#2
0
        public static string FormatXml(TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
        {
            XmlDocument doc;

            try {
                doc = new XmlDocument();
                doc.LoadXml(input);
            } catch (Exception ex) {
                // Ignore malformed xml
                MonoDevelop.Core.LoggingService.LogWarning("Error formatting XML file", ex);
                return(null);
            }

            var sw        = new StringWriter();
            var xmlWriter = new XmlFormatterWriter(sw);

            xmlWriter.WriteNode(doc, formattingPolicy, textPolicy);
            xmlWriter.Flush();
            return(sw.ToString());
        }