Table Of ContentOffice 2003 XML
for Power Users
MATTHEW MACDONALD
Office 2003 XML for Power Users
Copyright ©2004 by Matthew MacDonald
Originally published by Apress in 2004.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN 978-1-59059-264-9 ISBN 978-1-4302-0707-8 (eBook)
DOI 10.1007/978-1-4302-0707-8
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: John Paul Mueller
Editorial Board: Dan Appleman, Craig Berry, Gary Cornell, Tony Davis, Steven Rycroft,
Julian Skinner, Martin Streicher, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski
Assistant Publisher: Grace Wong
Project Manager: Beth Christmas
Copy Editor: Ami Knox
Production Manager: Kari Brooks
Production Editor: Laura Cheu
Proofreader: Linda Seifert
Compositor: Diana Van Winkle, Van Winkle Design Group
Indexer: James Minkin
Artist: Diana Van Winkle, Van Winkle Design Group
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 233 Spring
Street, 6th Floor, New York, NY, 10013 and outside the United States by Springer-Verlag GmbH &
Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany.
In the United States: phone 1-800-SPRINGER, email orders@springer-ny.com, or visit
http://www.springer-ny.com. Outside the United States: fax +49 6221 345229, email
orders@springer.de, or visit http://www.springer.de.
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite
600, Berkeley, CA 94706. Phone 510-549-5930, fax 510-549-5939, email info@apress.com, or visit
http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The companion content for this book is available to readers at http://www.apress.com in the
Source Code/Downloads section.
For Faria
Contents at a Glance
About the Author...............................................................................................xiii
About the Technical Reviewer......................................................................xv
Acknowledgments................................................................................................xvii
Introduction........................................................................................................xix
Chapter 1 Understanding XML...................................................................1
Chapter 2 XML Schema ................................................................................37
Chapter 3 Mapping XML in Excel ..........................................................79
Chapter 4 Mapping XML in Word ..........................................................121
Chapter 5 Exporting and Importing XML in Access ...................153
Chapter 6 WordML and SpreadsheetML ...............................................173
Chapter 7 Transforming XML .................................................................215
Chapter 8 Managing Workflow with XML Web Services...............249
Chapter 9 InfoPath ..................................................................................285
Index......................................................................................................................315
v
Contents
About the Author...............................................................................................xiii
About the Technical Reviewer......................................................................xv
Acknowledgments................................................................................................xvii
Introduction........................................................................................................xix
Chapter 1 Understanding XML ............................................................1
A Brief History of XML ....................................................................................1
The XML Philosophy .............................................................................................2
XML vs. HTML ....................................................................................................4
What XML Is Not....................................................................................................5
The Rules of XML..................................................................................................7
The Document Prolog........................................................................................7
Elements and Tags..............................................................................................9
Element Contents.............................................................................................11
Element Relations ............................................................................................12
Attributes ..........................................................................................................14
Entity References..............................................................................................16
Comments.........................................................................................................17
Well-Formed XML ............................................................................................19
Types of XML Documents ..................................................................................20
Data-Centric XML ............................................................................................20
Document-Centric XML ..................................................................................23
XML Namespaces ....................................................................................................25
Namespaces and Attributes.............................................................................29
Testing Namespaces.........................................................................................30
The Promise of XML in Office 2003 ..........................................................30
Word ..................................................................................................................31
Excel ..................................................................................................................32
Access ................................................................................................................33
Visio ...................................................................................................................33
PowerPoint, Outlook, and FrontPage..............................................................34
InfoPath.............................................................................................................34
The Last Word ......................................................................................................35
vii
Contents
Chapter 2 XML Schema ............................................................................37
The Role of XML Schema ..................................................................................38
XML Schema and Other Standards.................................................................39
Testing a Schema ..............................................................................................39
Basic Schemas ......................................................................................................41
Validating with the Simple Schema ................................................................42
Simple and Complex Types ..............................................................................44
Anonymous and Named Types .......................................................................46
Groups and Sequences ....................................................................................51
Minimums, Maximums, and Lists ..................................................................54
Mixed Content Type .........................................................................................56
Attributes ..........................................................................................................58
The Any Element ..............................................................................................60
Data Types.............................................................................................................61
Numeric Data Types.........................................................................................61
String Types.......................................................................................................63
Date and Time Types ........................................................................................63
The Boolean Type .............................................................................................64
Binary Types......................................................................................................64
A Typed Schema ...............................................................................................65
Deriving Custom Data Types..........................................................................67
Restricting String Length .................................................................................68
Restricting Number Ranges.............................................................................69
Restricting Values with Enumerations............................................................70
Restricting Values with Patterns ......................................................................70
Schemas and Namespaces ..................................................................................72
Locating Schemas................................................................................................74
The Last Word ......................................................................................................77
Chapter 3 Mapping XML in Excel...................................................79
XML Lists ...............................................................................................................80
Importing and Exporting a Basic XML List ....................................................80
Editing, Refreshing, and Exporting the List....................................................83
Sorting and Filtering Lists................................................................................86
Mapping Cells to XML.......................................................................................89
Importing Complex Structures .....................................................................92
Tables and Headers ..........................................................................................92
Multitabular Data .............................................................................................96
Relational (or Nested) Data .............................................................................99
Irregular Rows.................................................................................................102
viii
Contents
Importing XML Documents with Schemas ..................................................102
Aggregating and Analyzing XML .................................................................107
The Total Row .................................................................................................107
Calculated Columns, Formulas, and Charts ................................................108
Data Mining.........................................................................................................112
Retrofitting Existing Templates .....................................................................113
Getting the Data in Visual Basic 6 .................................................................116
The Last Word ....................................................................................................118
Chapter 4 Mapping XML in Word ...................................................121
Viewing an Ordinary XML File ...................................................................122
Mapping XML with a Schema ..........................................................................124
Managing the Schema Library ......................................................................126
Creating an XML Document with a Schema ................................................128
Saving Mapped XML ......................................................................................132
Opening Mapped XML...................................................................................134
Schema Validation..........................................................................................135
Using Schemas with Mixed Mode.................................................................138
Elements with Attributes ...............................................................................138
Using Multiple Schemas ................................................................................140
Hybrid Word XML Documents ..........................................................................143
The Memo Template Solution .......................................................................143
Placeholders and Tag View ............................................................................148
Document Protection ....................................................................................149
Gaps in the Word 2003 XML Support ............................................................151
The Last Word ....................................................................................................152
Chapter 5 Exporting and Importing XML in Access.....153
Exporting XML ....................................................................................................154
The Exported XML..........................................................................................155
The XML Schema ...........................................................................................157
The XSL Transform .........................................................................................159
Exporting Related Tables ...............................................................................160
Other Export Options.....................................................................................165
Customizing Exported XML with a Query....................................................167
Importing XML ....................................................................................................169
Programmatic Importing and Exporting ..................................................171
The Last Word ....................................................................................................172
ix
Contents
Chapter 6 WordML and SpreadsheetML ......................................173
The Role of WordML and SpreadsheetML ..................................................173
How the Office XML Formats Work...............................................................174
Dissecting SpreadsheetML ............................................................................176
A Simple SpreadsheetML Document............................................................177
Spreadsheets with Noncontiguous Ranges ..................................................182
Numbers and Formulas .................................................................................183
Formatted Spreadsheets ................................................................................185
Mapped Spreadsheets....................................................................................187
Dissecting WordML ...........................................................................................188
A Simple WordML Document........................................................................190
Formatted Documents...................................................................................194
Documents with Graphics.............................................................................197
Mapped Documents ......................................................................................199
Getting More Information About WordML Structures ................................201
Programming with the Office XML Formats ...........................................202
Mining Data ....................................................................................................202
Creating Documents ......................................................................................209
The Last Word ....................................................................................................213
Chapter 7 Transforming XML ...........................................................215
The XSL Standard..............................................................................................216
The Role of XSLT .............................................................................................217
XSLT Basics.........................................................................................................218
The Empty Stylesheet.....................................................................................218
Building Basic Templates...............................................................................220
Copying Node Values .....................................................................................224
Applying Templates........................................................................................226
Conditional Templates...................................................................................229
XSLT and Namespaces ...................................................................................230
Converting XML to HTML ................................................................................230
HTML and Tables ...........................................................................................233
Changing the Structure of XML.....................................................................236
XSLT with WordML and SpreadsheetML ......................................................236
Office and XSLT ..............................................................................................237
XSLT in Word ...................................................................................................241
Changing WordML to Your Custom XML .....................................................246
The Last Word ....................................................................................................248
x
Contents
Chapter 8 Managing Workflow with XML Web Services....249
An Overview of the Expense Report Workflow.....................................250
Installing the Prerequisites ...................................................................254
Internet Information Services .......................................................................255
.NET Framework and Web Matrix .................................................................256
The SOAP Toolkit ............................................................................................257
Building the Expense Report Workflow ..................................................258
Creating the Database....................................................................................258
Creating the Web Service Objects .................................................................262
Creating the Web Service ...............................................................................264
Exposing the Web Service ..............................................................................268
Creating the Excel VBA Macro .......................................................................271
Running a Test ................................................................................................277
Creating the Summary Web Page ..................................................................278
Other Scenarios................................................................................................283
The Last Word ....................................................................................................284
Chapter 9 InfoPath................................................................................285
An Overview of InfoPath ..............................................................................285
When to Use InfoPath ....................................................................................286
The Limits of InfoPath ...................................................................................287
Designing InfoPath Forms ............................................................................288
Creating a Form Based on a Schema ............................................................290
Filling Out the Form .......................................................................................296
Complex Forms ..............................................................................................298
Publishing Forms ...........................................................................................303
InfoPath and Web Services ..........................................................................305
Designing a Query Form................................................................................309
Designing a Data Form ..................................................................................311
Submitting an Expense Report......................................................................312
The Last Word ....................................................................................................313
Index....................................................................................................................315
xi