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