Identify lists

Hi,


I’m trying to identify the different elements of every lists available in a document.

The issue I face is that I actually can’t rely on the list id of a list.

The following code with the document attached always returns a list id of 1 even though there are actually two separate lists in this document.

Document document = new Document(“list id test.docx”);
NodeCollection paragraphs = document.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph paragraph : paragraphs) {
if (!paragraph.isListItem()) {
continue;
}
System.out.print("List ID: " + paragraph.getListFormat().getList().getListId() + " Text: " + paragraph.toString(SaveFormat.TEXT));
}
Could you help me identifying the different lists in a document?
Thank you very much.
Best regards,

Hi David,


Thanks for your inquiry. There is only one ‘List’ in your document; however, paragraphs with a, b, c and d numbering are on second ‘List Level’. You can identify those paragraphs using following code:
for (Paragraph paragraph : paragraphs) {
if (!paragraph.isListItem()) {
System.out.println(paragraph.getListFormat().getListLevelNumber());
}
System.out.print("List ID: " + paragraph.getListFormat().getList().getListId() + " Text: " + paragraph.toString(SaveFormat.TEXT));
}
Best regards,