Using XML with Microsoft® Office 2003 Robert Grauer and Maryann Barber Committed to Shaping the Next Generation of IT Experts.1 Exploring Microsoft® Office 2003 - Grauer and Barber Objectives Define XML; explain how XML differs from HTML. Describe the XML syntax; create an XML document using the Notepad accessory. Explain how Internet Explorer is XML-enabled and how Notepad is not. Map a Word document to an XML schema. Import and refresh XML data into an Excel worksheet. Import XML data into an Access database; export an Access query as an XML file. Modify an XML document to reference a schema and a style sheet. Describe the purpose of Microsoft Office InfoPath 2003. Exploring Microsoft® Office 2003 - Grauer and Barber 2 What is XML? XML (eXtensible Markup Language) is an industry standard for structuring data across applications, operating systems, and hardware devices Latest of evolution of Markup Languages SGML – Standardized General Markup Language HTML – Hypertext Markup Language XML is “data about data” i.e., it describes the data and not the formatting Exploring Microsoft® Office 2003 - Grauer and Barber 3 So What is a Markup Language? Rich Text 2 bedroom/2 bath – $600 per month – (305) 111-2222 HTML <B><I> 2 bedroom/2 bath – $600 per month – (305) 111-2222 </I></B> XML <Apartment> <Description> 2 bedroom/2 bath </Description> <Rent> $600 per month </Rent> <Telephone> (305) 111-2222 </Telephone> </Apartment> Exploring Microsoft® Office 2003 - Grauer and Barber 4 What is eXtensible? XML tags are created by the user <Apartment> <Description> 2 bedroom/2 bath </Description> <Availability> Immediate Occupancy </Availability> <Rent> $600 per month </Rent> <Amenities> Swimming pool; close to campus </Amenities> <Telephone> (305)111-2222 </Telephone> <Security> 1 month </Security> </Apartment> Define additional tags as you need them Exploring Microsoft® Office 2003 - Grauer and Barber 5 A Simple XML Editor Notepad can be used to create and edit XML XML specification (optional) Comment statement XML tags have element name between brackets and are case sensitive; the ending tag has a slash in front of the name Root element permits multiple occurrences of Apartment element within one document Exploring Microsoft® Office 2003 - Grauer and Barber 6 Internet Explorer is XML-Aware Nested elements are indented for ease of understanding Plus and minus signs show collapsed and expanded elements XML tags are in color Data is in bold face Exploring Microsoft® Office 2003 - Grauer and Barber 7 An Iterative Process Create document in Notepad, then view document in Internet Explorer Click Refresh button to view updated document Open editor to modify document Enter and save the changes Exploring Microsoft® Office 2003 - Grauer and Barber 8 Errors are Not Permitted Internet Explorer will not open a document with errors Explanation of the error is provided Open editor to correct the error Enter, then save the changes, and then click Refresh button to see document in Internet Explorer XML tags are case sensitive; these tags do not match Exploring Microsoft® Office 2003 - Grauer and Barber 9 There is a Better Way . . . InfoPath 2003 enables a developer to create XML forms in the familiar Office environment Underlying schema is displayed in a task pane Exploring Microsoft® Office 2003 - Grauer and Barber 10 InfoPath 2003 – User View The user enters data into a form which is converted to an XML document InfoPath is included in the Office 2003 Enterprise edition, but not in Office Professional; see office.microsoft.com/infopath for additional information Exploring Microsoft® Office 2003 - Grauer and Barber 11 Microsoft Word . . . Multiple résumés are received by an organization, but cannot be processed electronically The solution is to convert the documents to XML, then process the results in an application where you can search and select for specific requirements Exploring Microsoft® Office 2003 - Grauer and Barber 12 Schema is Created Independently Required elements Creating a schema is a course unto itself; our purpose is not to describe the detailed design, but rather to make you aware of its function and overall layout Data type is specified; e.g., years are integer numbers Exploring Microsoft® Office 2003 - Grauer and Barber 13 Attach the Schema Pull down Tools menu, click Templates and Add-Ins command The same schema can be attached to multiple documents Indicate path of the schema Contents of the résumé will be checked against schema requirements Exploring Microsoft® Office 2003 - Grauer and Barber 14 Map the Document XML Structure pane XML tags are nested within one another The Name element is the parent of the FirstName and LastName elements Exploring Microsoft® Office 2003 - Grauer and Barber 15 Save the XML Document Specify XML as file type Save data only Exploring Microsoft® Office 2003 - Grauer and Barber 16 The XML Document Reference to the schema Internet Explorer is XML-aware Plus and minus signs show collapsed and expanded elements Exploring Microsoft® Office 2003 - Grauer and Barber 17 Microsoft Excel – Import XML Data XML data is imported as a list XML Source pane displays the schema and previews data Exploring Microsoft® Office 2003 - Grauer and Barber 18 Analyze the Data . . . PercentOfGoal field is added Conditional formatting is used to highlight employees who make goal Company totals are also calculated Pivot table provides additional analysis Exploring Microsoft® Office 2003 - Grauer and Barber 19 View the Pivot Table Pivot table displays totals for each city Click Refresh button if underlying data changes Worksheet tabs are colored Exploring Microsoft® Office 2003 - Grauer and Barber 20 Update the Data in XML Click to edit document View original XML document Click Refresh button to see updated data This value will change Save modified document Change the data; e.g., to 3100000 Exploring Microsoft® Office 2003 - Grauer and Barber 21 Refresh the Data Right click anywhere within the list to display contextsensitive menu Refresh the data Exploring Microsoft® Office 2003 - Grauer and Barber 22 Microsoft Access – Import XML Table Exploring Microsoft® Office 2003 - Grauer and Barber 23 Create a Query from both Tables Run the query Dynaset displays the results of the query Exploring Microsoft® Office 2003 - Grauer and Barber 24 Export the Query as XML Location of the XML document Exploring Microsoft® Office 2003 - Grauer and Barber 25 Three Separate Documents XML document has references to a schema and a style sheet The style sheet is created in Notepad Exploring Microsoft® Office 2003 - Grauer and Barber 26 Add Reference to Style Sheet Open XML editor No reference to a style sheet and hence data is unformatted Add reference to style sheet Exploring Microsoft® Office 2003 - Grauer and Barber 27 The Data is Formatted Click Refresh button to view updated document XML document can be stored locally Exploring Microsoft® Office 2003 - Grauer and Barber 28 Return to Apartment Listings . . . Exploring Microsoft® Office 2003 - Grauer and Barber 29 It is a Mail Merge . . . The main document (form letter) The data source Exploring Microsoft® Office 2003 - Grauer and Barber 30 With One Hitch Pull down File menu to Get External Data Microsoft Word does not recognize XML as a data source (you will have to ask Microsoft for the reason) One solution is to start Access, import the XML document into a new database, and then use that database as the data source for the mail merge Select Apartment Listings XML document and click Import button Exploring Microsoft® Office 2003 - Grauer and Barber 31 Set Access as Data Source Select newly created Access Locate data source database and click the Open button Exploring Microsoft® Office 2003 - Grauer and Barber 32 Complete the Mail Merge Mail Merge toolbar appears automatically when data source is added Mail merge fields are added to the document Merged document is a separate file Click Next to create the merged document Exploring Microsoft® Office 2003 - Grauer and Barber 33 In Conclusion . . . XML (eXtensible Markup Language) is a public standard and freely available. The XML syntax, known officially as the XML recommendation, was developed by the World Wide Web Consortium (commonly known as W3C), a public organization with the sole purpose of creating standards or recommendations for the Internet. The creation of the standards is an open process and any individual or company can join and participate. (W3C also published the HTML specification.) You can learn more about the organization and its standards by visiting their Web site at www.w3.org. Exploring Microsoft® Office 2003 - Grauer and Barber 34 rgrauer@miami.edu www.prenhall.com/grauer Exploring Microsoft® Office 2003 - Grauer and Barber 35