1
votes

I have a java program that search rsidR="00CA303F" inside document.xml(unzipped of DOCX).

<w:sdtContent>
<w:r w:rsidR="00CA303F">
    <w:rPr>
        <w:rFonts w:cs="Arial"/>
        <w:b/>
        <w:sz w:val="18"/>
        <w:szCs w:val="18"/>
        <w:lang w:val="en-US"/>
    </w:rPr>
    <w:t>17-Jan-14</w:t>
</w:r>
</w:sdtContent>

The problem: if i change something like the date in the docx and after i save the file, this rsidR change! and im not able to find it next time in my program.

How i can freeze-fixed it? or which other fixed-element can i add to w:r for find it after saving file?

Solutions(not working) that i tryed: I added other tags(hoping they will not change), i tryed for example: w:rsidRDefault, w:id, w:val, w:rsidRPr to this w:r, but Word wont be able to open file docx after.

2

2 Answers

0
votes

Word or the OpenXML file format do not offer a direct way to add an ID to an element, which is also persisted if the document is edited.

As a workaround, you can create a character style which you then apply to the run of text you are interested in. Then you can search for the w:rStyle element with the correct character style in the w:val attribute:

<w:r w:rsidRPr="00E05157">
    <w:rPr>
        <w:rStyle w:val="MyCharacterStyle"/>
    </w:rPr>
    <w:t>17-Jan-14</w:t>
</w:r>
0
votes

It should be possible to assign a unique id to the containing w:sdt (in the descendant w:sdtPr/w:id/@w:val). See for example the docx4java documentation for sdtPr.

A good explanation of rsid's, and how they are used by MS Word, is in What's up with all those rsid's. In many application it is harmless to completely ignore them.