Beispiel #1
0
        public static string FormatXml(TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
        {
            XmlDocument doc;

            try {
                doc             = new XmlDocument();
                doc.XmlResolver = null;                 // Prevent DTDs from being downloaded.
                doc.LoadXml(input);
            } catch (XmlException ex) {
                // handle xml files without root element (https://bugzilla.xamarin.com/show_bug.cgi?id=4748)
                if (ex.Message == "Root element is missing.")
                {
                    return(input);
                }
                MonoDevelop.Core.LoggingService.LogWarning("Error formatting XML file", ex);
                IdeApp.Workbench.StatusBar.ShowError("Error formatting file: " + ex.Message);
                return(input);
            } catch (Exception ex) {
                // Ignore malformed xml
                MonoDevelop.Core.LoggingService.LogWarning("Error formatting XML file", ex);
                IdeApp.Workbench.StatusBar.ShowError("Error formatting file: " + ex.Message);
                return(input);
            }

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

            xmlWriter.WriteNode(doc, formattingPolicy, textPolicy);
            xmlWriter.Flush();
            return(sw.ToString());
        }
        public static string FormatXml(TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
        {
            var doc = new XmlDocument();

            doc.XmlResolver = null;             // Prevent DTDs from being downloaded.
            doc.LoadXml(input);

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

            xmlWriter.WriteNode(doc, formattingPolicy, textPolicy);
            xmlWriter.Flush();
            return(sw.ToString());
        }
        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());
        }
Beispiel #4
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());
        }