Browse DevX
Sign up for e-mail newsletters from DevX


Designing Smart Documents in Office 2003 : Page 2

Today, most organizations have a wealth of Office documents that contain critical information, but finding, extracting, and reusing that information programmatically remains a largely unrealized goal. Fortunately, that's changing as XML processing in Microsoft Office 2003 grows up.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Getting Started
For this article, the goal is to create a simple customer information template that contains basic customer information and a particular item that customer has purchased. You'll see more about the exact entities required by this document later, but you can look at the downloadable Customer Information.dot template file (see Figure 1) to get a good idea of the overall content. To complete the application as described here, you'll need VB 6.0, Visual Studio.NET 2003, and Office 2003 installed on your development machine. The PIA (primary interop assemblies) for Office 2003 ship with the product, and the full installation installs them, but you do need to explicitly select the PIA if you perform a custom Office installation. Finally, I suggest you install the Office SmartDocument SDK, because that provides some useful tools and important schema files.
Note: If you have a pre-beta installation of VS.NET 2005 (Whidbey) and VS.NET 2003 you may have problems running Office applications in debug mode, I was able to eliminate these problems by uninstalling the pre-beta installation.

Here are the basic steps involved in creating a SmartDocument application:

  • Create a document template that users will fill out to submit information.
  • Create an XSD schema that logically relates to the content (entities) in the document template that you intend to capture.
  • Apply the XSD schema to the document.
  • Create shims which implement the ISmartDocument interface and hookup the shim implementation to call managed code. Shims in this case are unmanaged DLL's that are restricted to loading assemblies built in managed code.
  • Implement the ISmartDocument interface in your managed code. The managed code encapsulates all the business logic for the application.
  • Create an XML manifest for downloading the application-dependent files. You could also create MSI packages, which could contain XML manifest files for deployment.
Much of this work has been done for you in the downloadable sample code. Extract the download contents into a folder, and follow these steps:
  1. The folder path is critical for this example because the manifest path points to the various DLLs and Schema based on the file path. Make sure you change the appropriate path in the CustomerManifest.xml file so it matches the path where you extracted the sample code.
  2. Find the Data.xml file (which the sample uses instead of a database), and note its location. You'll need to alter the hard-coded path for that document in the GetData() method of the DocumentUtils class.
  3. Find the DocumentShim.dll and register it using regsvr32.
  4. Finally, compile the .NET solution with the "Register for COM interop" option on. You can locate this option as one of the build properties by browsing through the project property page in VS.NET.
  5. If you installed the SmartDocument SDK, locate and run "Disable XML Expansion Pack Manifest Security" from the program's menu option. You should be able to locate this reg file in the Tools menu group.
  6. Open the Customer Information.dot template in Word, go to "Tools, Templates and Add-ins," and click on the XMLExpansion packs option. If you see any available or attached XML expansion packs, delete them and then add them back from the extracted folder.
After making these configuration alterations you're ready to follow along with the rest of this article.

Author's Note: The XML Expansion pack requires a trusted certificate; to avoid this you run the DisableManifestSecurity reg file. Also, make sure that your Word macro security setting is not set to High.

Creating the Document Template
Open Word and insert two tables as shown in the enclosed sample "Customer Information.dot" document (see Figure 1). The first table will hold customer details, while the second one holds a purchased item. Add the text information inside the table as shown, and save the document as a Word template (.dot) file. You won't see the XML nodes shown in Figure 1 until after you apply the schema.
Figure 1. Template View: After applying a schema, the Word template contains two tables and displays the XML tags from the schema.
Creating the XML Schema
You need to define an XML schema containing the elements and attributes that represent the information required by the document template. The Customer.xsd schema (see Listing 1) fulfills that purpose for this sample application. It's often useful to use attributes for the data you intend to repurpose and elements to display data in document. For example, suppose you want to capture an element with the value "United States Of America" from a database. You fetch the identifier (the primary key value) value for "United States Of America" from the database and assign it to an attribute node while displaying "United States Of America" as element text. This provides users with the flexibility to change text whenever appropriate—for example, the user might override the text to display "USA"; but cannot change the attribute value that identifies the row in the database, letting you repurposed the information easily later. Associating such primary keys with display text in intelligent documents is important, as you want to provide users with maximum flexibility to change the content as needed without impacting the validity of the business process.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date