Connecting Documents to an External Data Source

As mentioned, a source document is the single WordprocessingML document that contains the data necessary to be connected to an external data source by a conforming hosting application and/or data source access application. The presence and parameters of this connection are specified within the <mailMerge> element. This element enables WordprocessingML documents to be connected to an external data source by specifying the following data:

  • Where the external data is located (e.g., file path)

  • What type of data the external data source contains (e.g., database and spreadsheet)

  • How the data will be accessed

Consider a document containing static WordprocessingML constructs such as paragraphs in addition to two WordprocessingML mail merge fields calling for Courtesy Title and Last Name data.

Dear {MERGEFIELD "Courtesy Title" \m} {MERGEFIELD "Last Name" \m},

Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.

Sincerely,

If the following WordprocessingML was added to this document, this document would become a source document rather than just a standard WordprocessingML document, as the <mailMerge> element specifies the elements and attributes necessary to enable the hosting applications and/or data source access applications to connect the document to an external data source.

<w:mailMerge><w:dataType w:val="database" />
  <w:query w:val="SELECT * FROM Table1" />
  <w:dataSource r:id="rId1" /></w:mailMerge>

Here, the <dataType> and <dataSource> elements specify that the given document shall be connected to the external data source referenced by the @r:id attribute's value of rId1. While connected to the external data source, the merged document together with the hosting application and/or data source access application may extract data from the external data source as specified by the <connectString >and <query> elements.