How to merge with xml data source

Here is a question asked by one of our users in e-mail. Our current policy is that we generally don't provide technical support answers via e-mail. All support questions should be posted on our forums.

So I post and answer it here.

I am looking for an example on how to use an xml data source for the Aspose.Word - doument.MailMerge.Execute method....any samples anywhere on this?

That is easily done with .NET DataSet.ReadXml ability. First, create XML file with data. Here is an example of XML dataset containing one table with three rows of data:



FirstName1
LastName1
AccountName1
StreetAddress1


FirstName2
LastName2
AccountName2
StreetAddress2


FirstName3
LastName3
AccountName3
StreetAddress1

Your document should contain the correspondent mail merge fields:

«CONTACT_FIRSTNAME»,
«CONTACT_LASTNAME»,
«ACCOUNT_NAME»,
«CONTACT_MAILING_STREET»

To mail merge the document with xml data the following code can be used:

DataSet ds = new DataSet();

ds.ReadXml("DataSet1.xml"));

doc.MailMerge.Execute(ds.Tables[0]);

That's all. Simple, isn't it?