public static string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
		{
			XmlDocument doc;
			try {
				doc = new XmlDocument ();
				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 ();
		}
Beispiel #2
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 ();
		}
Beispiel #3
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 TextWriterWrapper (TextWriter wrapped, XmlFormatterWriter formatter, TextWriterWrapper currentWriter)
			: this (wrapped, formatter)
		{
			PreviousWrapper = currentWriter;
		}
		public TextWriterWrapper (TextWriter wrapped, XmlFormatterWriter formatter)
		{
			this.Wrapped = wrapped;
			this.formatter = formatter;
		}