Microsoft Office 2003 Editions: Overview of Developer TechnologiesSeptember 2004
and custom XML schema support, these data existed as simply numbers displayed in the cells of a spreadsheet or somewhere within a Word document range. You were required to know the structure of the document (e.g. spreadsheet cell reference, named range, Word structure or bookmark) in order to read or set the value. If you moved the item to another position in the document, you had to find and change every line of code that accessed the value. With an XML schema mapped to the document, you can read or set the value by referring to an XPath statement based on the schema. This method of access is independent of where the data appears in the document because it references the XML structure. The following example shows how to set a value to XML-mapped data in Word using an XPath expression. This both simplifies the code by requiring only one statement and makes the solution more robust by separating the access method to the data from the document layout or formatting.
<xs:element name="Company" type="xs:string"/>
<xs:element name="NumberItems" type="xs:integer"/>
This XPath statement refers to the <Company> element:
This statement is one way to set the value of the data in the Word document associated with the <Company> element using an XPath statement in Visual Basic:
ActiveDocument.XMLNodes(1).SelectSingleNode( "/n:PurchaseOrder/n:Company ", "xmlns:n='uri:myNS'" ).Text = “NewValue”
This ease of working with XML schemas applies to how to access data in documents programmatically, how to format data, how to incorporate data from external sources, and how to extract data from a document or file. In addition, Word and Excel provide events relating to
© 2006 Microsoft Corporation. All rights reserved. Page 8 By using or providing feedback on these materials, you agree to the attached license agreement.
To comment on this paper or request more documentation on these developer features, contact us at . We look forward to hearing from you.