Excel-XML - What's All About
Excel-XML - What's All About
Excel-XML - What's All About
To learn more about this course, read the overview in the center of this
page or the table of contents in the left column. Then click Next to
start the first lesson.
how it works, and then see how some of the programs in the Microsoft Office System help you use XML.
Goals
After completing this course you will be able to:
• Use and follow basic XML terminology and concepts such as tags, schemas, and transforms.
• Five self-paced lessons and two practice sessions for hands-on experience.
• A short test at the end of each lesson; tests are not scored.
• A Quick Reference Card you can take away from the course.
Multiple data sources, multiple uses for the data from each source.
Suppose you run the human resources department of a medium-sized company. Your staff sees lots of resumés,
usually in the form of documents or e-mail messages.
Wouldn't it be great if you could automatically copy the names, addresses, and lists of job skills from those resumés?
And even better, if you could use your computers to match those skills with open positions? And best of all, if the
same process prepared a report on your department's performance for your manager?
You can do those things (and more) with XML. You can extract data from various original sources, store that data in
one place so you know just where to find it, and use the data again whenever and wherever you need it.
For example, do you need to report budget data for the past three years? However you store that data, if it's in XML,
you can select what you need and import it into a document, worksheet, or database — whatever the situation
requires.
Suppose you run a veterinary clinic and you want to use XML to store data for your various animal clients. Your XML
data files will contain the data for each animal. Each piece of that data is surrounded by a tag, and each tag describes
what the piece of data means. The combination of tag and data is called a node.
The illustration shows a sample XML data file for a cat named Izzy. The tags are the combinations of angle brackets
and text:
and so on.
Tags actually consist of two parts, an opening tag and a closing tag like so:
<BREED> … </BREED>
The forward slash (/) is what makes a tag a closing tag. The opening and closing tags surround any data, like so:
<BREED>Siamese</BREED>
In XML, the tags are designed to clearly describe every piece of data. If someone asks what all those tags mean, you
can say that they mean whatever you need them to mean. That's a part of what makes XML "extensible." In this
case, you know what "yes," "no," and "Izzl138bod" all mean.
Because the tags describe the structure and meaning of the data, then any computer program or system that
supports XML can understand that data and put it to use. For instance, you could load the cat's name and the owner's
name from the data into a vaccination report and a payment request simultaneously.
Those are just a couple of examples of how you can put XML to work. You can use your data in reports, Web pages,
and databases, and that's just for starters. When you need to exchange data, XML can meet almost any business,
scientific, or academic need.
Declarations
In addition to data and tags, XML data files contain declarations, root elements, and attributes. The names may
sound mysterious, but after some brief definitions, you'll see that these are all simple and logical.
Root element
XML declarations are statements in the data file that identify it and other files it works with. In this illustration, the
first declaration states that the file is an XML file. (If that's not stated, programs don't know how to work with it.) The
Attribute
second declaration names a file that governs data structure for this file and other files of its sort. The third declaration
names a file that is used to control the appearance of the data, and that allows an XML system to reorganize the
Tags and data
data.
Root element means one tag that contains all the other tags, and all the data in each particular record. XML files
require root tags. For this vet's data files, the root tag is the individual animal client.
Attributes store information about the tags and the data in them. The types of information in attributes are defined
by the XML for each kind of tag. In this example, every animal client must have a patient number as an attribute of
the root element.
Tags and data are, of course, the principal components of the file. You can also think of tags and data as child
elements contained by the <CAT> … </CAT> root element.
<name>Izzy</name>
</cat>
If you provide an opening tag, you must provide a closing tag (with the
exception of empty tags, which we explain below). <cat> ... </cat>
Incorrect
Some tags, called empty tags, do not require closing tags because they Horizontal rule
include the closing forward slash as part of the tag. The example shows
tags for inserting a horizontal rule and a line break. <hr/>
Line break
<br/>
You must enclose all attribute values in single or double quotation marks. Correct
patient_id="389467"
Incorrect
patient_id=389467
All tags must be nested correctly. The sequence of closing tags must Correct
mirror the sequence of opening tags.
<cat>
<name>Izzy</name>
</cat>
Incorrect
<cat>
<name>Izzy</cat>
</name>
> >
You may hear the phrase "well-formed XML" and wonder what that means. It's simple: XML is well-formed when it
follows a small set of strict rules.
For example, XML is case sensitive. It cares about capital letters. For XML data to be well-formed, the tags must all
use an identical mix of capital letters and small letters. So <CAT> ... </CAT> is well-formed, but <CAT> ...
</Cat> is not.
You don't have to know all the rules, but if you'd like to know them, they're listed in this table. Here's what you do
have to know: You can share XML data among users and systems only when that data is well-formed. If it is not well-
formed, your XML system stops working (which means that your business stops working).
But that's a good thing. Really. Because, if a block of XML data is not well-formed, chances are that it's also corrupt.
XML's innate ability to alert you early can save you from a variety of later problems, such as having to correct
inaccurate numbers in your reports or clean corrupted data out of your files.
In the practice session, you'll violate one of the rules for well-formed XML and see how Word 2003 handles that error.
Practice
Ready to get acquainted with some XML data? In this practice session, you'll see how easy it is to create an XML file in Word
2003. You'll also see how Word behaves when it encounters XML data that isn't well-formed.
Important To complete this practice session, you must use Microsoft Office Word 2003 or Microsoft Office Professional
Edition 2003. You cannot complete this session by using the version of Word in Microsoft Office Standard Edition 2003.
Tips
• If the practice instructions aren't visible, or disappear when you click in Word, click the Word Help taskbar button
and then click the Auto Tile button on the upper-left corner of the instructions.
• If the practice instructions cover up Word, click the Auto Tile button on the upper-left corner of the instructions.
Before you begin
Make sure to close Word if it is already running.
Test Yourself
Which of these helps make XML extensible?. The ability to create tags as needed to describe a piece
of data. You got it. If you need more tags to define your data, you're free to add them.
To create an XML file in Word 2003, you: Save a document as an XML file, Right! Start with Save As
(on the File menu), and in the Save As dialog box, select XML document from the Save as type list..
Don't let the term intimidate you. Schema is just another word for structure or organization. In XML, a schema
contains the rules for what can and can't be in the various parts of an XML data file.
It's important to keep separate the rules in a schema and the rules for well-formed XML. The rules for well-formed
XML dictate how your resident expert or IT department has to build a data structure, including any schemas. A
schema is XML, and as such it must conform to the rules for well-formed XML.
In contrast, the rules in a schema dictate what can and can't reside in a given data structure. For example, a schema
may say that a certain tag can contain only dates and another can contain only prices. Without a schema, the date
field in your well-formed XML could contain text, and your price field could contain dates. Your XML would be like a
grammatical, but meaningless, sentence.
A schema can be contained in a data file, or it can be a separate file linked to the data file. Either way, whenever
you use a data file in concert with a schema, that data file is said to conform to that schema. If your IT department
creates a separate schema file, that schema file uses the file name extension .xsd. Data files use the file name
extension .xml.
Anatomy of a schema
Declarations
Optional sequence declaration (controls the order of the tags in the data file)
Data type
Schemas can become extremely complex, and your IT department will probably create them for you, after talking to
you about what types of data you need and how the XML system should work. Knowing what schemas look like will
help you talk to IT about them. The illustration shows a schema setting rules for the <CAT> ... </CAT> tag set
discussed in the previous lesson.
This schema contains a set of declarations. The declarations control the type of data that each tag can contain. In
this case, the sequence declaration also controls the order of the tags that reside inside the <CAT> root element.
Any data file that uses this schema must have its tags in the order shown. Elsewhere in the illustration, the data
type declarations control the type of data that each tag in a data file can contain: a string of letters, a number, or a
Yes/No choice. As you'd expect, tags in a data file cannot contain a different type of data than what the schema
declares. This is how a schema can help to validate your XML data.
(You may recall that an earlier section, “Anatomy of an XML data file,” also mentioned declarations. One of those
declarations stated which schema would govern the data file's content. So the two groups of declarations are
related, logically and functionally.)
So how does all this affect you? If you are a veterinarian, and you need to have your files contain additional
information about your animal clients, such as their color or markings, you would have the person in charge of your
XML add tags for that data. Adding those tags will also require changes to the schema for the file. If you do not
change the schema, the new tags will be considered illegal, and the system will stop working. Simple schema
changes may be very quick, but any schema change is important because it creates a new rule for your data.
Because you can change your schemas as your computing and data needs evolve, XML files can be adapted to new
situations and requirements without rebuilding the files from scratch. Like the tags, the schema is extensible.
Test Yourself
A schema enforces rules for well-formed XML. False. Good! The rules in a schema define what can
and cannot reside in a given data file. The rules for well-formed XML ensure that you can exchange your
data with other users and XML systems.
A schema contains _____: Declarations. Yes! The declarations in a schema control which tags and data
can and cannot reside in a data file.
All XML systems must use .xsd files. False. That's it. Schemas can be separate files that use the .xsd file
name extension, or they can reside in data files that use the .xml file name extension.
For example, say your sales department stores its data in Excel
workbooks, and your accounting department needs that information
imported into a database. A transform can write data from preselected
Transforms can automate data exchange. cells in the worksheet into the correct fields in the database.
Regardless of how you need to use your data, a transform can help.
Depending on the steps that are built into them, transforms act as data processors. For instance, you can
sort or filter data as you write it from your XML data store to a document or spreadsheet program.
So, you can publish a newsletter listing new business partners by state, but omitting their street addresses.
You can also use your XML products inventory to create a Web catalog without showing your supplier's unit
prices, or sort salespeople by region or manager when you generate the latest diagram of your organization.
What's more, transforms can also control your visual displays — the appearance of your data. For instance,
you can use a transform to print sales data so that it looks like it came from a spreadsheet program, even if
it didn't, or vice-versa.
In addition to creating Web pages, you can also use transforms to deploy multiple versions of a Web site.
You can store all your data in one place and create a set of transforms that make your data look good in
And because more companies, schools, and government agencies are adopting XML, software companies
are providing transforms that work with their programs. In the future, you'll be able to quickly find and
download transforms that either meet your needs or that your IT folks can easily adjust to suit your
purpose. This means that your first investment in XML will enable you to do more and more as time goes
by.
Anatomy of a transform
Test Yourself
You use transforms to: Sort, filter, and perform other types of processing on data. Good! Keep in mind
that you can also use transforms to control the display of data.
You use transforms to convert data into XML. False. Indeed! Converting data into XML is a different
process, and that's the next lesson.
Like it or not, your business will have to write its own transforms. False. That's right. A growing
number of software providers are creating transforms that you can either use right away or adapt to do a
particular job.
When you see how much XML can do, and will be
doing, you understand why several Office 2003
programs have XML built right in. Built-in XML makes
this powerful language much easier to use. See how
smoothly you can move from standard Office files to
their XML versions, and you'll know why XML is
gaining so much acceptance worldwide.
Office 2003 programs support XML in ways that make sense for them.
Several of the programs in the Microsoft Office Professional Edition 2003 support XML. Each program
furnishes XML tools that coincide with the nature of the program itself. The earlier practice showed how
Word 2003 allows you to save files as XML. You can also attach schemas and transforms to your Word 2003
documents.
Excel 2003, on the other hand, uses the concept of a map for working with XML. You create a map by
linking the cells in a worksheet to elements in a schema. You can't save a workbook as XML unless you first
create a map (which you'll see how to do in the practice session for this lesson).
The best way to learn how an Office 2003 program supports XML is to open Help for that program and
search on "XML" for more information.
As for XML schemas, transforms, or data from other suppliers, Microsoft Office Professional Edition 2003
programs are ready to work with those.
Practice
The first practice session showed you how Word 2003 works with XML. Now you'll see how Excel 2003
works with XML. In this practice session, you'll create an XML map for Excel, and you'll open an XML data
file in Excel as an XML list.
Important To complete this practice session, you must use Microsoft Office Excel 2003 or Microsoft
Office Professional Edition 2003. You cannot complete this session by using the version of Excel in Microsoft
Office Standard Edition 2003. In addition, you need to download a sample XML data file. Follow the
instructions below to download the sample XML data file:
1. To keep these instructions in front of you, print this page. Right-click the page, then click Print. In
the Print dialog box, click Preferences and set the orientation to Landscape. Click OK, then click
Print.
2. Next, click this link: Practice XML file. The link takes you away from this page of instructions to a
download page titled "Excel 2003 Sample: XML File."
3. On the right of that download page, click the Download button.
Note If you use Windows® XP Service Pack 2, you need to follow some additional steps. After
you click the Download button, the File Download - Security Warning dialog box appears. Click
Run. The Internet Explorer - Security Warning dialog box then appears. Click Run again. Skip
step 4 below and follow step 5 and step 6 to finish downloading the sample file.
Tips
• If the practice instructions aren't visible, or if they disappear when you click in Excel, click the
Excel Help taskbar button and then click the Auto Tile button in the upper-left corner of the
instructions.
• If the practice instructions cover up Excel, click the Auto Tile button in the upper-left corner of
the instructions.
Before you begin
Make sure to close Excel if it is already running.
Excel 2003 Sample: XML File - How to use XML in Excel 2003
Excel 2003 > Working with Data > Working with XML.
Applies to
Microsoft Office Excel 2003
Note The information in this article assumes that you have a basic knowledge of
Extensible Markup Language (XML). If you'd like more basic information, see
Manage Information with XML in Microsoft Office Professional Edition 2003.
One of the most powerful features of Microsoft Office Excel 2003 is one you can't
really see: support for user-defined XML schemas. In plain English, that means you
can add XML schemas (a schema is just a structure) and data to your workbooks,
regardless of where the XML originated. Excel automates most of the processes for
you. All you need to do is open the file and decide how you want to use the data.
You can:
• View the data in an XML list Use this option when you want to see all
your data in one list. Lists act as cohesive units. If it helps, think of them as
worksheets within larger worksheets. You can manipulate the data in a list
separately from the surrounding worksheet. For example, you can sort data,
rearrange rows, and, to a limited extent, rearrange the columns in a list without
affecting the surrounding cells.
• View the data in a read-only workbook Use this option when you or
others need to view the data in a file but don't need—or want—to manipulate it.
Read-only workbooks can provide a fast way to create business reports and other
types of files that you don't want users to change. When you select this option,
Excel displays the data in a static grid.
• Create a map from the structure and import data into the map When
you use the XML Source task pane to create a map, you link or bind a cell in a
worksheet to an element in the XML file. Importing data into the map populates
the cells with data. This is the most flexible and powerful option for working with
XML data. For example, say your sales department stores its data as XML, and
you need to create a report that summarizes sales activity for each month. When
the sales department posts new data, you can import that data into a map or set up a
system that updates your worksheets automatically. This figure shows a worksheet
with a populated map. Excel surrounds the mapped cells with a blue border.
4. Click one of the options in the Open XML dialog box, and then click OK.
If a message box appears, click OK to close it. Excel creates the list. Notice that
Excel adds all the data in the file to the list.
Depending on the structure of your source file, you may see a lot of repeated
data, such as names and dates. You can eliminate redundancies by using the Use
the XML Source task pane option when you open the file.
More information
The following links take you to more information about Excel and XML lists:
As a read-only workbook
Excel adds all the data in the file to the list and flattens the file, meaning it
displays the data in a standard grid instead of a list.
Depending on the structure of your source file, you may see a lot of repeated
data, such as names and dates. You can eliminate redundancies by using the Use
the XML Source task pane option when you open the file.
5. Drag the items (they're called elements) that you want to map from
the task pane to blank cells on your worksheet.
6. Select any one of the mapped cells. On the Data menu, point to XML, and
then click Import.
7. Use the Look in list to locate the source file you want to import.
Select the file, and then click Import.
8. Click OK to display the map in the task pane.
More information
The following links take you to more information about XML maps:
Tip
The following steps demonstrate another way you can open the XML Source task
pane and use it to create an XML map:
1. On the Data menu, point to XML and then click XML Source.
2. In the XML Source task pane, click XML Maps, and then click Add.
3. Use the Look in list to locate the XML file that you want to open, and then
click Open.
4. In the XML Maps dialog box, click OK to display the map in the XML
Source task pane.
5. Drag the items (they're called elements) that you want to map from the task
pane to blank cells on your worksheet.
6. Select any one of the mapped cells. On the Data menu, point to XML, and
then click Import.
7. Use the Look in list to locate the source file. Select the file, and then click
Import.
occur once in a given XML file, while repeating list elements can occur any number
of times. For example, if you create the expense report in the Practice exercise at the
end of this article, you'll use a combination of nonrepeating elements (such as an
employee name) and repeating list elements (such as a description of each expense
item and the cost of each item).
Keep these facts in mind:
• The XML Source task pane uses several icons to denote repeating list
elements. For the Practice exercise, pay attention to these:
• Excel automatically formats repeating list elements as XML lists when you
drag the elements onto the worksheet. That makes it easy to distinguish between
repeating and nonrepeating elements, because lists automatically provide the
AutoFilter button.
• If you place repeating list elements next to each other on the same row, Excel
includes each adjacent element in a single large XML list.
• If you place repeating elements by themselves, or next to nonrepeating
elements, Excel formats them as individual XML lists.
Import data
Export data
1. On the Data menu, point to XML, and then click Export. The Export XML
dialog box appears.
2. Use the Save in list to navigate to the folder to which you want to export the
data, and then click Export.
Save data
Note When you use the Save As command, Excel also makes available the
older XML Spreadsheet file format. If you save your data using that format,
other users must have Microsoft Excel 2002 or later to work with your data.
More information
The following links take you to more information about importing and exporting
data:
When the Open XML dialog box appears, click Use the XML Source task
pane, and then click OK.
1. Drag the ns1:EmployeeName element from the XML Source task pane to
cell B1, and then drag the ns1:Department element to cell D1.
2. Drag the ns1:ManagerName element to cell B3, and then drag the ns1:Date
element to cell D3.
1. Select any one of the mapped cells. On the Data menu, point to XML, and
then click Import.
2. Use the Look in list to locate the sample file, and then click Import.
Excel populates the mapped fields. Notice that Excel automatically applies XML
list formatting to the repeating elements (in this case, the expense items) in the
map.
Practice
The first practice session showed you how Word 2003 works with XML. Now you'll see how Excel 2003
works with XML. In this practice session, you'll create an XML map for Excel, and you'll open an XML data
file in Excel as an XML list.
1. To keep these instructions in front of you, print this page. Right-click the page, then click Print. In
the Print dialog box, click Preferences and set the orientation to Landscape. Click OK, then click
Print.
2. Next, click this link: Practice XML file. The link takes you away from this page of instructions to a
download page titled "Excel 2003 Sample: XML File."
3. On the right of that download page, click the Download button.
Note If you use Windows® XP Service Pack 2, you need to follow some additional steps. After
you click the Download button, the File Download - Security Warning dialog box appears. Click
Run. The Internet Explorer - Security Warning dialog box then appears. Click Run again. Skip
step 4 below and follow step 5 and step 6 to finish downloading the sample file.
Tips
• If the practice instructions aren't visible, or if they disappear when you click in Excel, click the
Excel Help taskbar button and then click the Auto Tile button in the upper-left corner of the
instructions.
• If the practice instructions cover up Excel, click the Auto Tile button in the upper-left corner of
the instructions.
Before you begin
Make sure to close Excel if it is already running.