2.1.382 Part 1 Section 17.14.35, uniqueTag (Unique Value for Record)
a. The standard does not define the contents of this element.
-
Word defines this element to contain a val attribute that is defined by the XML Schema base64Binary datatype.
b. The standard says that this element is used to maintain a relationship between the records within an external data source and a given merged WordprocessingML document.
-
Word uses this element to maintain a relationship between the records within an external data source and a given source WordprocessingML document.
c. The standard does not state how this element should be populated when the column containing unique data for a record is empty.
Word computes the unique tag, when empty, to be a base64-encoded value using the following algorithm:
Utility function 1:
-
#define nPrimeLast 4294967291 __int32 LHashMM( __int32 l, __int32 dl ) { l = 131 * l + dl; if (l >= nPrimeLast) { l -= nPrimeLast; } return l; }
Utility function 2:
-
__int32 LGetHashWz(const WCHAR *wzText) { int cch = lstrlen(wzText); __int32 lhash = 0L; for (int i = 0; i < cch; i++) { lhash = LHashMM(lhash, wzText[i]); } return lhash; }
Utility function 3:
-
__int32 DwRowHash(thisRow) { __int32 lwHash = 0L; for(int i = 0; i < TotalNumberOfColumnsInTheDataSource; i++) { Retrieve the value in the i-th column of thisRow as a Unicode String wzData; __int32 l = LGetHashWz(wzData); if(l) { lwHash = LHashMM(lwHash, l); } } return lwHash; }
Unique tag computation algorithm:
WCHAR wzUniqueTag[64] = {0};
*((__int32*) wzUniqueTag) = DwRowHash(the_row_containing_this_record);
return the wzUniqueTag as the uniqueTag;