Unexpected numbering ids when importing HTML with multiple nested ordered lists

When creating a new Document with HTML where a list item contains multiple ordered lists, list items in subsequent nested ordered lists are associated with existing numberings.

HTML:

<html>
<ol>
  <li>
    A child list containing one element:
    <ol>
      <li>
        List 1
      </li>
    </ol>
    Another child list containing one element:
    <ol>
      <li>
        List 2
      </li>
    </ol>
  </li>
  <li>
    A child list containing two elements:
    <ol>
      <li>
        This element is made part of List 1
      </li>
      <li>
        This element is made part of List 2
      </li>
    </ol>
  </li>
</ol>
</html>

DOCX:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
  xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
  xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
  xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
  xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
  xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
  xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
  xmlns:v="urn:schemas-microsoft-com:vml"
  xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
  xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
  xmlns:w10="urn:schemas-microsoft-com:office:word"
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
  xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
  xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
  xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
  xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
  xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">  <!-- Generated by Aspose.Words for .NET 24.9.0 -->
  <w:body>
    <w:p>
      <w:pPr>
        <w:rPr>
          <w:rStyle w:val="Hyperlink" />
          <w:b />
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:b />
          <w:color w:val="FF0000" />
          <w:sz w:val="24" />
        </w:rPr>
        <w:t xml:space="preserve">Created with an evaluation copy of Aspose.Words. To remove all limitations, you can use Free Temporary License </w:t>
      </w:r>
      <w:hyperlink r:id="rId4" w:history="1">
        <w:r>
          <w:rPr>
            <w:rStyle w:val="Hyperlink" />
            <w:b />
          </w:rPr>
          <w:t>https://products.aspose.com/words/temporary-license/</w:t>
        </w:r>
      </w:hyperlink>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="0" />
          <w:numId w:val="1" />
        </w:numPr>
        <w:ind w:left="720" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">A child list containing one element: </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="1" />
          <w:numId w:val="1" />
        </w:numPr>
        <w:ind w:left="1440" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">List 1 </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:ind w:left="720" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">Another child list containing one element: </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="1" />
          <w:numId w:val="2" />
        </w:numPr>
        <w:ind w:left="1440" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">List 2 </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="0" />
          <w:numId w:val="1" />
        </w:numPr>
        <w:ind w:left="720" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">A child list containing two elements: </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="1" />
          <w:numId w:val="1" />
        </w:numPr>
        <w:ind w:left="1440" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">This element is made part of List 1 </w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:numPr>
          <w:ilvl w:val="1" />
          <w:numId w:val="2" />
        </w:numPr>
        <w:spacing w:after="240" />
        <w:ind w:left="1440" w:hanging="280" />
        <w:jc w:val="left" />
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">This element is made part of List 2 </w:t>
      </w:r>
    </w:p>
    <w:sectPr>
      <w:headerReference w:type="default" r:id="rId5" />
      <w:footerReference w:type="default" r:id="rId6" />
      <w:pgMar w:header="720" w:footer="720" />
      <w:cols w:space="720" />
    </w:sectPr>
  </w:body>
</w:document>

I would expect a new numbering to be created for items in the third nested ordered list.

@alex.moss

When importing HTML that contains multiple nested ordered lists, it is common to encounter issues with numbering IDs, especially when the nested lists are not treated as separate entities. In your case, it seems that the items in the nested ordered lists are being associated with existing numbering, which is not the expected behavior.

To resolve this issue, you can manually manage the numbering of the lists in your document. Here are a few strategies you can consider:

  1. Create Separate Lists for Nested Ordered Lists: Instead of relying on the automatic numbering, you can create separate list instances for each nested ordered list. This way, each list will maintain its own numbering sequence.

  2. Restart Numbering: If you want to restart the numbering for each nested list, you can use the isRestartAtEachSection property when creating your lists. This property allows you to specify that the numbering should restart at each section, which can help in managing nested lists effectively.

  3. Specify List Levels: You can specify the list level for each item in your nested lists. This can be done by setting the list level number explicitly when adding items to the list. This way, you can control how the items are numbered based on their hierarchy.

Here is a code example that demonstrates how to create separate lists and manage their numbering:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create the first ordered list
List list1 = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
builder.getListFormat().setList(list1);
builder.writeln("A child list containing one element:");

// Create the first nested ordered list
List nestedList1 = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
builder.getListFormat().setList(nestedList1);
builder.writeln("List 1");

// Create another nested ordered list
List nestedList2 = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
builder.getListFormat().setList(nestedList2);
builder.writeln("List 2");

// Create the second ordered list
List list2 = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
builder.getListFormat().setList(list2);
builder.writeln("A child list containing two elements:");

// Add items to the second nested list
builder.getListFormat().setList(nestedList1);
builder.writeln("This element is made part of List 1");
builder.getListFormat().setList(nestedList2);
builder.writeln("This element is made part of List 2");

doc.save("Output.docx");

In this example, separate lists are created for each nested ordered list, allowing you to manage their numbering independently. Adjust the list templates and properties as needed to fit your specific requirements.

By implementing these strategies, you should be able to achieve the desired behavior for your nested ordered lists when importing HTML into your document.

Sources:
[1]: Working with Lists in Aspose.Words for Java

@alex.moss As I can see numbering in DOC produced by Aspose.Words is the same as numbering in the source HTML:
out.docx (8.5 KB)

Output DOCX:

Source HTML:

That’s true, but because the numbering associations aren’t correct when a new item is added the numbering breaks:

@alex.moss
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27415

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like