I get XML-data in which I need to replace <Bold> elements with the corresponding attribute for bold and such. For this I do this:
Code
const BOLD_ON_Token = '<Bold>'; ... procedure ReplaceAttribute(aRichText: TWPRichText; aStartToken, aEndToken: string; aElement: TOneWrtStyle); var StartID, EndID: Integer; begin aRichText.Finder.ToStart; while true do begin if not aRichText.Finder.Next(aStartToken) then break; StartID := aRichText.Finder.DropMarkerAtFoundPosition(1); if not aRichText.Finder.Next(aEndToken) then break; EndID := aRichText.Finder.DropMarkerAtFoundPosition(0); if (StartID <> 0) and (EndID <> 0) then begin aRichText.TextCursor.SelectMarker(StartID, EndID); try aRichText.TextCursor.SelectedTextAttr.IncludeStyle(aElement); finally aRichText.TextCursor.CollectAllMarker; end; end; end; end;
Is this a correct procedure?
Later I remove the elements, using this (don't use wildcards);
Code
rtMessage.Finder.ToStart;
rtMessage.Finder.ReplaceAll(ITALIC_ON_Token,'');
rtMessage.Finder.ToStart;
rtMessage.Finder.ReplaceAll(ITALIC_OFF_Token,'');
rtMessage.Finder.ToStart;
rtMessage.Finder.ReplaceAll(BOLD_ON_Token,'');
rtMessage.Finder.ToStart;
rtMessage.Finder.ReplaceAll(BOLD_OFF_Token,'');
rtMessage.Finder.ToStart;
...
When I preview the text, things look fine, but when I save to file and open in Word, the elements are still here. Wrong procedure?
In the XML I would like to trim multiple newlines inside the text (in RTF they appear /line/lineCrLf/line/line/line.., where Cr = ascii 13 and Lf = ascii 10) and leave just one or two. Can anyone help me with a solution?
Thanks in advance.[/code]