Find Numbered List and its Issues in the document

Hi,
I have a requirement to read the numbered list from the document and find out the duplicates and out-of-order items in it. Could you please let me know if there is any easy way to accomplish this requirement using Aspose libraries.

Thanks

@Nizzam2024 List items in MS Word documents are simple paragraph with special properties. You can use the following simple code to detect list items in the document:

Document doc = new Document(@"C:\Temp\in.docx");
foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (p.IsListItem)
    {
        // The paragraph is a list item.
    }
}

Please see our documentation to learn how to work with lists:
https://docs.aspose.com/words/net/working-with-lists/

Hi @alexey.noskov,

Actually, I am able to read the numbered items from the document, but I need to find out the duplicates and out-of-order items in numbered list
Ex 1: Duplicates:

1 some testing text.
1 some testing text. 

is there any way in Aspose to provide the second ‘1’ as duplicate in numbered list

Ex 2: Out of order:

1. some testing text
a. some testing text
2. some testing text

the above list is in decimal format and item ‘a’ has been added. Any possibility in aspose that can flag that item ‘a’ as out of list order.

Thanks

@Nizzam2024 Could you please attach your sample document here for our reference? We will check your document and provide you more information.

@alexey.noskov these are the example documents

repeatedNumber.docx (24.1 KB)

out-of-order.docx (23.7 KB)

@Nizzam2024 Thank you for additional information. In your document the list items belongs to different lists. That is why they became out of order. In your case you can get actual list label and compare it with the previous or next item label. You can get list labels using the following code:

Document doc = new Document(@"C:\Temp\in.docx");
doc.UpdateListLabels();
foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (p.IsListItem)
    {
        Console.WriteLine(p.ListLabel.LabelString);
    }
}

@alexey.noskov - Is there any thing that can flag the out of order list, other than checking the previous and next items list labels

@Nizzam2024 You can check list id, the item belongs to:

Document doc = new Document(@"C:\Temp\in.docx");
doc.UpdateListLabels();
foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (p.IsListItem)
    {
        Console.WriteLine(p.ListFormat.List.ListId);
    }
}

but anyways it is required to compare the list ids of the list items.

1 Like