Figure 3-15. Exported XML file
When saving an XML map to a file, Excel adds the processing instructions. Our original
file was very basic and did not include them (of course, there??™s no harm in including them).
Building an XML Data Class
Now that we??™ve got an idea of what XML data services Excel provides us, let??™s build a class that
will give us an easy-to-use interface to this functionality. Before we begin, though, let??™s think
about what we??™d like our class to do:
??? We want it to bring in data from various XML data sources.
??? We want the ability to refresh the data in case the source file is updated (either manually
or through an automated process).
??? We want to append data from another file that conforms to the same XML schema.
CHAPTER 3 n USING XML IN EXCEL 2007 108
??? We want to be able to clear and reset the data bindings.
??? We want to be able to persist the data back to the original file or to a new file.
Those are some basic functions we??™d expect from this object, but what else might a class
of this type do for us?
??? Check for the existence of XML maps?
??? Enumerate XML maps?
??? Rename an XML map?
??? Add or delete XML maps?
Open a new workbook and add a new class module in the VBE. Name the class cXML.
Before we do any importing of XML data, it??™s a good idea to see if a map exists for our
data. Add a new public property and call it HasMaps. Normally, I would add a module-level
variable to hold the contents of this property, but the HasMaps property will be read-only.
Pages:
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130