Adding/Getting Comments based on character position
Home › Forums › WordprocessingML › Adding/Getting Comments based on character position
Tagged: comments
- This topic has 3 replies, 2 voices, and was last updated 9 years, 5 months ago by
Eric White.
-
AuthorPosts
-
September 15, 2016 at 11:59 am #3790
Eric White
KeymasterHi Gene,
I’m not fully clear on your question.
Comments have markup in the main document part to indicate the start and end of the location of the comment (w:commentRangeStart, w:commentRangeEnd). These elements are situated at the specific location in the document. Then the actual text of the comment is in the comments part, which you must find by following the location.
You will be interested in the following screen-cast:
Key point of that screen-cast: create a word document (without comment), copy the document, in the copy, insert a comment, then use the Open XML SDK productivity tool to compare the two. This will teach you about comment markup.
Cheers, Eric
September 15, 2016 at 1:48 pm #3794iunknown
ParticipantThank you Eric,
What I’m trying to do is pull the plain text and the comments out of the document, which I can do.
The problem I’m having is knowing where a comment starts and stops in the plain text version.I did find the CommentRangeStart and Stop but they don’t expose a document position, that I could find.
>>These elements are situated at the specific location in the document.
Based on this statement, I think the approach I have to take is while extracting the plain text, record the current position of any comment starts and stops…But that doesn’t work because of the nested nature of OpenXML.
ugh.
September 16, 2016 at 1:04 pm #3798Eric White
KeymasterYes, you are right, there is not an easy way to get the document position.
In a recent project (WmlComparer), a module that compares two DOCX files and produces a new document that contains the precise differences between them (with certain restrictions), I transform the DOCX into a new form that is an array of the precise content of the document. Each character and image in the document occupy a single element of the array. This array is put together in such a way that it is possible to reconstruct a valid Open XML document from it. This approach resolves the problems associated with the nested nature of Open XML. You may be interested in watching this screen-cast:
It’s a bit long of a screen-cast, but it can illuminate the proper approach to dealing with this issue.
I have in mind a generalization of that approach so that developers can do the type of operations that you want to do, i.e. count specific characters, insert comments at any specific point easily, and so on. Writing WmlComparer really helped me to formalize my thoughts about this issue.
Cheers, Eric
-
AuthorPosts
- You must be logged in to reply to this topic.