Free Support Forum - aspose.com

DocumentVisitor.visitBookmarkStart invoked in incorrect sequence

If you have two bookmarks abutting one another, then visitBookmarkStart will be invoked on the second bookmark prior to visitBookmarkEnd on the first.


e.g. the document:
[BookmarkOne]
[BookmarkTwo]

the (psuedo) code:
document.accept(new DocumentVisitor() {
visitBookmarkStart(bookmarkStart) {
“visitBookmarkStart called for $bookmarkStart”;
}
visitBookmarkEnd(bookmarkEnd) {
“visitBookmarkEnd called for $bookmarkEnd”;
}
});

The output will be:
visitBookmarkStart called for BookmarkOne
visitBookmarkStart called for BookmarkTwo
visitBookmarkEnd called for BookmarkOne
visitBookmarkEnd called for BookmarkTwo

The following behaviour is what I’d expect would be correct:
visitBookmarkStart called for BookmarkOne
visitBookmarkEnd called for BookmarkOne
visitBookmarkStart called for BookmarkTwo
visitBookmarkEnd called for BookmarkTwo

Aspose Version:
Implementation-Title: Aspose.Words for Java
Implementation-Version: 10.2.0.0
Implementation-Vendor: Aspose Pty Ltd
Release-Date: 2011.06.30

Hi

Thanks for your request. Could you please attach your document here for testing? We will check the issue and provide you more information.

Best regards,

Example document attached to original post.


- Simon

Hi

Thank you for additional information. Actually, Aspose.Words returns the correct order of bookmarks. If you take a look inside the document you can make sure. I saved the document as DOCX for convenience and extracted an internal XML:

<w:p w:rsidR="008C0E0C" w:rsidRDefault="001B44AD">

<w:r>

<w:t>Start of Document</w:t>

</w:r>

</w:p>

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD" />

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD" />

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD">

<w:bookmarkStart w:id="0" w:name="firstBookMark" />

<w:r>

<w:t>First Bookmark</w:t>

</w:r>

</w:p>

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD">

<w:bookmarkStart w:id="1" w:name="secondBookMark" />

<w:bookmarkEnd w:id="0" />

<w:r>

<w:t>Second Bookmark</w:t>

</w:r>

</w:p>

<w:bookmarkEnd w:id="1" />

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD" />

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD" />

<w:p w:rsidR="001B44AD" w:rsidRDefault="001B44AD">

<w:r>

<w:t>End of Document</w:t>

</w:r>

</w:p>

As you can see, order is the same as Aspose.Words returns.

Best regards,