Slow Formating with XML using XML Addon

SyntaxEditor for WPF Forum

Posted 9 years ago by Ken Hanson
Avatar
Actipro,

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();

try
{

//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();
w.xmlEditor.Document.Language.RegisterXmlSchemaResolver(schemaResolver);

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;

w.xmlEditor.Document.SetText(s);

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


}
catch (Exception ex)
{
}


w.ShowDialog();


Best Regards,

Ken

Comments (1)

Posted 9 years ago by Ken Hanson
Avatar
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.

Thanks,

Ken
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.