Working on re-engineering an existing merge process, so it’s not ideal.
The problem I have is that when i’m trying to find the Nodes in the document to represent an iterative block, the tags i’m looking for can be in the middle of a run. The Nodes are then being used to duplicate the content within the nodes for the number of iterations specified.
All works well when the starting tag “<<&foreach” and the end tag “<<&endfor>>” are in a run on their own (i.e. have whitespace around them, but problems occur when the tag is within a Run
e.g. If the Run contains “Extraneous Text<<&foreach”, what I am after is a Node that simply contains “<<&foreach”.
Similar problem occurs if the end tag is within a run
e.g. “Spurious Text<<&endfor>>MoreText”
I’ve looked at using the SplitRun code -
private static Run SplitRun(Run run, int position)
{
Run afterRun = (Run)run.Clone(true);
afterRun.Text = run.Text.Substring(position);
run.Text = run.Text.Substring(0, position);
run.ParentNode.InsertAfter(afterRun, run);
return afterRun;
}
but as I am looping through the Run collection, it causes issues as it modifies the collection
Is there a way to get a Run object for a portion of a run ?
i.e. if the Run contains “Text<<&Foreach>>Text”, I want to get a Run containing only the “<<&Foreach>>” from within that run.
Failing that, is there a good way of replacing the “<<&foreach” and “<<&endfor>>” within a document with a Bookmark ?
I can see how to move a document builder to the Paragraph containing the run, but not how to move the cursor to the start of the relevant tag to insert the bookmark there