예제 #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());
        }
예제 #2
0
        public string FormatText(PolicyContainer policyParent, string mimeType, string input)
        {
            XmlFormattingPolicy xmlPol = policyParent.Get <XmlFormattingPolicy> (mimeType);
            TextStylePolicy     txtPol = policyParent.Get <TextStylePolicy> (mimeType);

            return(FormatXml(txtPol, xmlPol, input));
        }
예제 #3
0
        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());
        }
예제 #4
0
        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());
        }
예제 #5
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());
        }
        public void SetFormat(XmlFormattingPolicy policy)
        {
            this.policy = policy;
            Update();
            TreeIter it;

            if (store.GetIterFirst(out it))
            {
                listView.Selection.SelectIter(it);
            }
            if (policy.Formats.Count == 0)
            {
                boxScopes.Hide();
                buttonAdvanced.Show();
            }
            else
            {
                boxScopes.Show();
                buttonAdvanced.Hide();
            }
        }