Saving document produces error: "Start and end node should have the same grand parent"

Hi,
I’m using your component to open word documents and immediately save (or export in this case) them as xhtml. This works for most of my files, however on a few I get the following error:

System.ArgumentException: Start and end node should have the same grand parent. at Aspose.Words.CompositeNode

The documents have a number of mail merge fields within them.
I’m afraid I can’t post examples due to the sensitive nature of the documents.
Is there anything I can try to enable me to process these documents?

Many thanks
Matthew Rose

Hi

Thanks for your request. You can try to use DocumentExplorer to review a structure of the document. Most likely there is field that starts in one section and ends in other. But it is difficult to say what the problem is without document.
You can remove all confidential content from the document and attach it here or just try to recreate the problem on a simple document.
Which version of Aspose.Words are your using? Have you tried using the latest version?
https://releases.aspose.com/words/net
Maybe problem is already resolved.
Best regards.

Many thanks for the speedy reply.

I have identified the field causing the problem, however as it is a
merge field I can’t change the data within it. Removing the field
causes the document to convert properly.

The field is a {FORMTEXT} field; however it doesn’t seem to span sections.
I’m using version 6.0.1 .net version (I upgraded today to see if this had been resolved).
Many thanks

Hi
Different section is just example. This could be a table or any other composite nodes. So, could you provide me simple document that will allow me to reproduce the problem on my side?
Best regards.

Hi,

Sorry for the delay in providing a document. I have attached a document which is causing the error.
The field that I believe is causing the problem is next to the “School” text.

Many thanks

Matthew

Hi
Thank you for additional information. I managed to reproduce the problem and created new issue #7266 in our defect database. I will notify you as soon as it is fixed.
You are right the reason of the problem is field after “School” text. You can remove and insert this field using MS Word to resolve this issue.
Best regards.

Thank you for your speedy response.
These documents are generated from a mail-merge type process, so we have little to no control over the data that is input into them; is there anything we can do in the component to work around the error?

Many thanks
Matthew

Hi
Thanks for your request. As a workaround you can try remove fields from your document, (field values will not be deleted, we will remove only FieldStart, FieldEnd, FieldSeparator and field code nodes) See code below:

// Open document.
Document doc = new Document(@"Test110\in1.doc");
// Get collections of FiledStart, FieldEnd and FieldSeparator nodes
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
NodeCollection fieldSeparators = doc.GetChildNodes(NodeType.FieldSeparator, true);
NodeCollection fieldEnds = doc.GetChildNodes(NodeType.FieldEnd, true);
// We will store nodes that should be removed in this temporary list
ArrayList removeList = new ArrayList();
foreach (FieldStart start in fieldStarts)
{
    // Add to remove list nodes that represens field code
    Node currNode = start.NextSibling;
    while (currNode.NodeType != NodeType.FieldSeparator)
    {
        removeList.Add(currNode);
        currNode = currNode.NextSibling;
        if (currNode == null)
            break;
    }
}
fieldStarts.Clear();
fieldSeparators.Clear();
fieldEnds.Clear();
// Remove field codes
foreach (Node node in removeList)
{
    if (node.ParentNode != null)
        node.Remove();
}
// Save output docuemnt
doc.Save(@"Test110\out.html");

Hope this helps.
Best regards.

Hi,
Thank you for your workaround; I have reprocessed all of the documents which have this problem and they all now seem to work.
Your help is very much appreciated.
Many Thanks
Matthew

The issues you have found earlier (filed as 7266) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by alexey.noskov.