Extract encompassed bookmarks list

Hello,

I manipulate bookmarks in Word document.
I want to get emcompassed bookmarks into an other one.
But in the document : Etiquettes_148x105.docx (23.2 KB), the bookmark ‘Enrobantpicto2’ is not concidered like a encompassing Bookmark (IsComposite)

I have following functions for extract bookmark and know a list of encompassed bookmarks.

public static IList<Node> ExtractContent(Node startNode, Node endNode, bool isInclusive)
{
    IList<Node> nodes = new List<Node>();

    Node originalStartNode = startNode;
    Node originalEndNode = endNode;

    while (!new[] { NodeType.Body, NodeType.Cell, NodeType.HeaderFooter }.Contains(startNode.ParentNode.NodeType))
        startNode = startNode.ParentNode;

    while (endNode.ParentNode.NodeType != startNode.ParentNode.NodeType)
        endNode = endNode.ParentNode;

    bool isExtracting = true;
    bool isStartingNode = true;
    bool isEndingNode;
    // The current node we are extracting from the document.
    Node currNode = startNode;

    while (isExtracting)
    {
        Node cloneNode = currNode.Clone(true);
        isEndingNode = currNode.Equals(endNode);

        if ((isStartingNode || isEndingNode) && cloneNode.IsComposite)
        {
            if (isStartingNode)
            {
                ProcessMarker((CompositeNode)cloneNode, nodes, originalStartNode, isInclusive, isStartingNode, isEndingNode);
                isStartingNode = false;
            }

            if (isEndingNode)
            {
                ProcessMarker((CompositeNode)cloneNode, nodes, originalEndNode, isInclusive, isStartingNode, isEndingNode);
                isExtracting = false;
            }
        }
        else
            nodes.Add(cloneNode);

        // Move to the next node and extract it. If next node is null that means the rest of the content is found in a different section.
        if (currNode.NextSibling == null && isExtracting)
        {
            Section nextSection = (Section)currNode.GetAncestor(NodeType.Section).NextSibling;
            currNode = nextSection.Body.FirstChild;
        }
        else
        {
            currNode = currNode.NextSibling;
        }
    }

    return nodes;
}

private static void ProcessMarker(CompositeNode cloneNode, IList<Node> nodes, Node node, bool isInclusive, bool isStartMarker, bool isEndMarker)
{
    if (!IsInline(node))
    {
        if (!(isStartMarker && isEndMarker))
        {
            if (isInclusive)
                nodes.Add(cloneNode);
        }
        return;
    }

    if (node.NodeType == NodeType.FieldStart)
    {
        if ((isStartMarker && !isInclusive) || (!isStartMarker && isInclusive))
        {
            while (node.NextSibling != null && node.NodeType != NodeType.FieldEnd)
                node = node.NextSibling;

        }
    }

    if (node.NodeType == NodeType.CommentRangeEnd)
    {
        while (node.NextSibling != null && node.NodeType != NodeType.Comment)
            node = node.NextSibling;

    }

    int indexDiff = node.ParentNode.ChildNodes.Count - cloneNode.ChildNodes.Count;

    if (indexDiff == 0)
        node = cloneNode.ChildNodes[node.ParentNode.IndexOf(node)];
    else
        node = cloneNode.ChildNodes[node.ParentNode.IndexOf(node) - indexDiff];

    bool isProcessing = true;
    bool isRemoving = isStartMarker;
    Node nextNode = cloneNode.FirstChild;

    while (isProcessing && nextNode != null)
    {
        Node currentNode = nextNode;
        isSkip = false;

        if (currentNode.Equals(node))
        {
            if (isStartMarker)
            {
                isProcessing = false;
                if (isInclusive)
                    isRemoving = false;
            }
            else
            {
                isRemoving = true;
                if (isInclusive)
                    isSkip = true;
            }
        }

        nextNode = nextNode.NextSibling;
        if (isRemoving && !isSkip)
            currentNode.Remove();
    }

    if (!(isStartMarker && isEndMarker))
    {
        if (cloneNode.HasChildNodes)
            nodes.Add(cloneNode);
    }

}

The Bookmark 'Enrobantpicto2 is not considered like IsComposite.
So the list return is empty.

Thanks by advanced.

@BASSETTI Bookmark in MS Word as well as in Aspose.Words Document Object Model is not a composite node, i.e. it does not have children. A bookmark consists of two marker nodes - BookmakrStart and BoormarkEnd. The content between these nodes is considered as bookmarked content.

So if it is required to get bookmarks inside another bookmark, it is require to get bookmarks between the outer bookmark’s BookmakrStart and BoormarkEnd nodes. But you should not that it is not mandatory that one bookmark is entirely inside another bookmark, they can intersect:

As you can see from the provided screenshot, the bookmark bk2 starts inside bookmark bk1, but ends outside it.

@alexey.noskov
So If I resume, a bookmark is not a composite node, only paragraph (and may be another node) can be composite.
If i need to get encompassed bookmarks, i need to get bookmark inside bookmark until i get bookmark end of this current bookmark.

@BASSETTI Yes, exactly.