public void SetText(string fragment) { fragment = fragment.Trim(); if (fragment.StartsWith("<")) //performance optimization, gridview will take long time if it is no xml document { if (XSConfiguration.Instance.Config.AlwaysPrettyprintFragments) { try { _edtFragment.Text = PrettyPrint.Execute(fragment, true, false, true); } catch { _edtFragment.Text = fragment; // MessageBox.Show(Application.Current.MainWindow, "Cannot prettyprint selected text:\n" + e.Message, // "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { _edtFragment.Text = fragment; } try { GridBuilder builder = new GridBuilder(); GridCellGroup root = new GridCellGroup(); //XmlDocument xmldoc = fragment.ToXmlDocument(); XmlDocument xmldoc = new XmlDocument(); //do this to remove #whitespace nodes xmldoc.LoadXml(fragment.ToXmlDocument().OuterXml); builder.ParseNodes(root, null, xmldoc.ChildNodes); _gridFragment.Cell = root; _gridFragment.FullExpand(); } catch (Exception) { _gridFragment.Cell = null; } } else { _edtFragment.Text = fragment; _gridFragment.Cell = null; } updateFolding(); }
private void mnuAppendToEditorAndPrettyprint_Click(object sender, RoutedEventArgs e) { string text = getStringInContext().Trim(WhitespaceChars); try { text = PrettyPrint.Execute(text, true, false, true); } catch { // text = getStringInContext(); } _editor.XmlEditor.AppendText(text); }
protected override void Execute(EditorFrame ef) { try { string xmlToProcess; try { ef.XmlEditor.Text.ToXmlDocument(); //we are interested if this throws an exception, nothing else xmlToProcess = ef.XmlEditor.Text; //MessageBox.Show(Application.Current.MainWindow, "Document is well-formed. No need to trim.", // "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch { xmlToProcess = XParser.Trim(ef.XmlEditor.Text); } try { ef.XmlEditor.Text = PrettyPrint.Execute( xmlToProcess, ef.Data.PrettyPrintData.Indent, ef.Data.PrettyPrintData.NewLineOnAttributes ); } catch { ef.XmlEditor.Text = xmlToProcess; } } catch (Exception e) { MessageBox.Show(Application.Current.MainWindow, "Error: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }