We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

TOC field issue

Hi support,

Please check the following code :

private void handleChildNodesTest(Node[] nodeCollection)
{
for (Node node : nodeCollection)
{
System.out.println("node start " + node.toString());

if (node.isComposite())
{
CompositeNode compositeNode = (CompositeNode) node;
if (compositeNode != null)
{
Node[] childNodes = compositeNode.getChildNodes().toArray();
handleChildNodesTest(childNodes);
}
}
else if(node.getNodeType() == NodeType.RUN)
{
Run run = (Run) node;
if(run != null)
{
System.out.println(run.getText());
}
}

if(node.getNodeType() == NodeType.FIELD_END)
{
FieldEnd fieldEnd = (FieldEnd) node;
if((fieldEnd != null) && (fieldEnd.getFieldType() == FieldType.FIELD_TOC))
{
System.out.println(“toc is ending here”);
}
}

System.out.println("node end " + node.toString());
}
}


@Test
public void testTOCField() throws Exception
{
Document doc = new Document(“C:\Temp\TOC.doc”);
for (Section section : doc.getSections())
{
Body body = section.getBody();
if ((body != null) && (body.getChildNodes() != null))
{
Node[] nodes = body.getChildNodes().toArray();
handleChildNodesTest(nodes);
}
}
}


Please note that the TOC field is ended after the start of the last paragraph (Paragraph@2820282). Is this expected ? Why the TOC fieldEnd is not before the end of its paragraph (Paragraph@63a663a6) ?
I attach console.txt and the Word document.

Please confirm,
Milan

Hi Milan,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Yes, this is expected. If you press Alt+F9 (Show field codes), you will see that TOC field is in the same paragraph as the main text. You can also open document using DocumentExplorer (Aspose.Words demo application) to inspect document’s structure.

Best regards.