Slow Formating with XML using XML Addon

SyntaxEditor for WPF Forum

Posted 10 years ago by Ken Hanson

I have my xml contained in a string, so I am using SetText to populate the Editor's Document. I found found that I must manualy cause the formater to cause the line breaks and indentation. When the XML document is moderatly large this formating takes an extreem amount of time.

I must be doing something wrong, here is the basics all broken down into a single set of statements.

EditSourceWindow w = new EditSourceWindow();


//note that the string 's' contains about 300k characters of well formed xml, which works, but is extreemly slow when formating

string s = _designer.CurrentDocument.SaveDocumentToString();

XmlSchemaResolver schemaResolver = new XmlSchemaResolver();

XmlTextFormatter formater = (w.xmlEditor.Document.Language as XmlSyntaxLanguage).GetTextFormatter() as XmlTextFormatter;
XmlOutliner outliner = (w.xmlEditor.Document.Language as XmlSyntaxLanguage).GetOutliner() as XmlOutliner;
formater.ElementSpacingMode = XmlElementSpacingMode.RemoveEmptyLines;
formater.AttributeSpacingMode = XmlAttributeSpacingMode.NormalizeWhitespace;

w.xmlEditor.IsOutliningMarginVisible = true;
w.xmlEditor.IsLineNumberMarginVisible = true;
w.xmlEditor.Document.OutliningMode = ActiproSoftware.Windows.Controls.SyntaxEditor.Outlining.OutliningMode.Default;


TextSnapshotRange tsr = w.xmlEditor.Document.CurrentSnapshot.SnapshotRange;
w.xmlEditor.Document.InsertText(TextChangeTypes.AutoFormat, 0, "");

catch (Exception ex)


Best Regards,


Comments (1)

Posted 10 years ago by Ken Hanson
A bit more information. It appears that the problem occurs because the xml I am passing in is not already nicely formated with cr/lf after elements, it is one long string, a properly formated xml string, but one long string.

I assumed that the formatter would be ok with this, but it seems to really bog down in this case.

I have implemented a pre-formating and things are much better, however I would presume this is a bug to be looked at, unless I'm missing something else.


The latest build of this product (v2020.1.1) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.