Creating Data-Bound Content Controls using the Open XML SDK and LINQ to XML
Data-bound content controls are a powerful and convenient way to separate the semantic business data from the markup of an Open XML document. After binding content controls to custom XML, you can query the document for the business data by looking in the custom XML part rather than examining the markup. Querying custom XML is much simpler than querying the document body. However, it’s a little bit involved to create data-bound content controls (but only a little bit). But there is a trick we can do – we can take a document that has un-bound content controls, generate a custom XML part automatically (inferring the elements of the custom XML from the content controls), and then bind the content controls to the custom XML part.
This approach has two benefits – first, it can serve as a way to conveniently create a document with data-bound content controls, and second, it serves to demonstrate exactly what you must do to create data-bound content controls.
This example uses the following approach:
Using Word 2007, you create a document with any number of content controls in it.
When creating each content control, you set the Tag of the content control to the desired XML element name in the custom XML.
You then run this example code on the document, which creates the custom XML part, creates the custom XML properties part, and then adds the markup to the body of the document that binds each content control to the custom XML.
This example uses the Open XML SDK V1 and LINQ to XML.
...
...
...
Eric White's Blog : Creating Data-Bound Content Controls using the Open XML SDK and LINQ to XML
No comments:
Post a Comment