Iterate over the document

Hi Tahir,

>>> Please check if bookmark name starts with _Toc.
This is exactly what I’m doing now… and the good thing is that word doesn’t allow anyone created bookmark starting with underscore.

Thanks,
Kumar

Hi Kumar,

Thanks for your feedback. Yes, MS Word does not allow user to create bookmark starts with underscore. Please let us know if you have any more queries.

Hi Tahir,

I’m iterating over a List with multiline (at the end of the list item, hit enter and then back space) list item. However, I’m not able to identify if the list item in the second line is part of the list or not.

When I’m iterating over it, the first line comes in as a paragraph-list, but the second paragraph (with text - Still part of the list), I’m not able to identify if it still part of the list item.

See screenshot and the attached document for better understanding.

List list = paragraph.getListFormat().getList();
if (list != null)
{

}

I tried to use paragraph.isListItem(), but didn’t help. Because of this, I’m for the treat the second list item as a fresh new List.

How to I get know that the second line/paragraph is still part of the list/listitem?

Thanks,
Kumar

Hi Kumar,

Thanks for your inquiry. The paragraphs with text “Still part of the list” and “again” are not list items. We have tested the scenario using following code example and have not found the shared issue. The Paragraph.IsListItem property returns correct value for all paragraphs. We suggest you please upgrade to the latest version of Aspose.Words for Java 16.1.0.

Document doc = new Document(MyDir + "list_simple.docx");
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    System.out.print(para.isListItem() + " - " + para.getListFormat().getList() + " - " + para.toString(SaveFormat.TEXT));
}

Hi Tahir,

I’m not complaining about the current behavior. I need a way to achieve the following.

  1. How to identify that the paragraph (with text - Still part of the list) is part of the list?
  2. How to identify that “Second” list item is part of the whole list?

Some more details
I’m building an XML out of the docx using Aspose API. All the list items should be part of my tag. With the current API, I end up creating separate list for each list item.

Thanks,
Kumar

Hi Kumar,

Thanks for your inquiry.
kumaraswamy.m:

  1. How to identify that the paragraph (with text - Still part of the list) is part of the list?
    Please use Paragraph.IsListItem property to check either a paragraph is an item in a bulleted or numbered list.
    kumaraswamy.m:
  2. How to identify that “Second” list item is part of the whole list?
    In your document, the paragraphs with text “Still part of the list” and “again” are not list items. So, Paragraph.IsListItem returns false for these two paragraphs.

Moreover, you can get the unique identifier of the list using List.ListId property as shown in following code example. Hope this helps you.

Document doc = new Document(MyDir + "list_simple.docx");
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : (Iterable)paragraphs)
{
    if (para.isListItem())
    {
        System.out.println(para.getListFormat().getList().getListId() + " - " + para.getText());
    }
}

If you are getting any incorrect results for any document, please share that document here for investigations.

Hi Tahir,

Probably I’m not explaining my question better.

I understand that “still part of the list” is not a list item.
However, how do I know “second” is a continuation of list item “Login to one”?

The structure is
List

  1. List item 1
    paragraph - not a list item
  2. List item 2
    End List

- How do I know, “List item 2” is continuation of “List item 1” as it’s numbered list is 2.
- Hos do I know “List item 2” is part of the above list?

As I said earlier, I want to write the above structure to an XML. Let me know if my question is not clear.

Thanks,
Kumar

Hi Kumar,

Thanks for sharing the detail. Please use List.ListId to check either “1. List item 1” and “2. List item 2” are from same list or not. For both items the List.ListId will be same. You may also use Paragraph.ListFormat.List property to check if both items belongs to same list. Please execute following code example to check the values of List.ListId and Paragraph.ListFormat.List. The values for both items will be same.

Document doc = new Document(MyDir + "list_simple.docx");
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : (Iterable)paragraphs)
{
    if (para.isListItem())
    {
        System.out.print(para.getListFormat().getList() + " - " + para.getListFormat().getList().getListId() + " - " + para.toString(SaveFormat.TEXT));
    }
}

A post was merged into an existing topic: Fetch comments across the word document irrespective of its parent node