Start and End Node should have the same parent error

Hi,

We are currently facing this issue in our Production system. I have attached the document for your perusal. Could you please help us in this regard?

Thanks
-Balaji

Hi,

Thank you for considering Aspose.

1. Make sure you use the latest version of Aspose.Word.

2. Please also post the code you use to process the document.

Thanks for your response. I do use the latest version of Aspose.

//Open Commitment.dot
Document doc = new Document("…");

//Mail Merge
doc.MailMerge.Execute(new string[] {…}, new object[] {…});

The above mentioned error occurs during MailMerge…

“Start and End Node should have the same parent”…

Document doc = new Document(System.IO.Path.Combine(DocPath, “COMMITMENT.dot”));

doc.MailMerge.Execute(

new string[] {“ListingAgent1Company”, “LISTINGAGENT1ADDRESS”, “SELLINGAGENT1COMPANY”, “LENDER1NAME”},

new object[] {“James Bond”, “Secret Agent”, “MI5 Headquarters”, “Milbank, London”});

return doc;

Thanks, now I can see it actually throws. I’ve logged the issue, we’ll try to fix it asap.

Thanks Dmitry for your response.

Do you have any ETA for this fix?

Thanks
-Balaji

Between 2nd and 3rd pages you have a section break inside a field and that does not go well with Aspose.Word at the moment. So you can get your document going if you move the section break outside of the field (like you have it between 1st and 2nd pages).

On a general note, to insert/remove sections into a document based on some condition I would recommend using sections or bookmarks rather than conditional IF fields.

One approach is to create a document that contains all possible sections of the report and remove unneded sections at runtime. Just create MS Word sections by inserting section breaks. You can have sections of the report that start on a separate page or continue on the same page. Then, in your code you can evalue and remove unneded sections from the document using the Document.Sections collection.

For example, for your COPY TO: blocks you can create just small section(s) that consist of those 4-5 lines. Let’s say it is the 2nd section in the document, then your code will look something like this:

if (!isNeedCopyToBlock)
doc.Sections.RemoveAt(1); //delete the 2nd section

The same concept applies for the bigger parts of the report on the following pages.

A similar appoach is to have several template documents and copy and move sections between them at runtime to build the final report, also use Sections, Section and Document.ImportNode. There are examples for this in the documentation and in the demo project (the Product Catalog Report).


Yet another technique is to wrap the regions of the report that you might need to remove into bookmarks and delete the content of these bookmarks at runtime:

if (!isNeedCopyToBlock)
doc.Bookmarks[“CopyToBmk”].Text = “”;



You actually have more section breaks inside the IF fields, not only between 2nd and 3rd page. You need to delete them all.

The easiest is to switch into display of field codes using Alt+F9 in MS Word and turn display of special characters on, then go and delete all those section breaks inside the fields.

I think you definitely need to change the approach and remove those huge IF field wrappers. Just insert normal Word section breaks and programmatically delete the sections before mail merge.

Thanks Romank for your timely response again.

Since these templates are created by Business, it is little hard to change and these documents are also used outside Aspose.

I will try to remove the section breaks out of the IF Blocks. Are you planning to release a fix/enhancement to handle this scenario? If yes, could you please let me the know the ETA?

Thanks for your great support.

-Balaji

Sorry we are not planning to release a hotfix for this in the meantime. This is a pretty custom case but it requires much development effort to overcome.

I must say the way you want to use the IF fields will not work with Aspose.Word.

Basically after Aspose.Word inserts data instead of the mail merge fields, the expression in the IF field needs to be evaluated so either the true of false part of the IF fields is shown in the document.

What this means is that when you take a document generated by Aspose.Word and open it in MS Word - it will not show the way you expect it to untill the user selects all text and presses F9 to update field results.

Aspose.Word cannot evaluate expressions in IF and other formula fields. In the current version only DOCPROPERTY and DOCVARIABLE fields are evaluated when you call Range.UpdateFields. We plan to implement full field evaluation engine, but this is several months away.