Microsoft Office Tutorials and References
In Depth Information
Sub BackupXML()
ActiveWorkbook.XmlMaps(“Root_Map”).Export _
Url:= “C:\SuppliersBackup.xml", Overwrite:=True
If Err.Number = 0 Then
MsgBox “Data exported to SuppliersBackup.xml successfully."
Else
MsgBox “There was a problem exporting to SuppliersBackup.xml."
Exit Sub
End If
End Sub
Warning Because the Overwrite argument is set to True , this procedure will delete any
existing data in the SuppliersBackup.xml file. Also, if the data list is empty, the procedure
will generate an error.
Mapping Schema Elements to Cells Using XPath
After you have mapped a schema to a workbook, you need to map every element you want to
appear in the worksheet to a range of cells so that you have a place for the associated XML
data to reside. You don’t need to assign every element in a schema to a cell or range; Excel will
skip any unused elements when it imports the data from your XML file.
You identify which element in a schema file to map to a cell using the XML Path language
(XPath). Although the full XPath specification is long and involved, it boils down to a system
of positively identifying the schema element to be mapped. In fact, XPath notation is very
similar to the notation you use to identify the path of a Microsoft Windows file. For exam­
ple, the path of a file might be C:\ExcelProg\MySuppliers.xml, which indicates that the
MySuppliers.xml file is in the ExcelProg directory on the C drive. The difference between the
XPath language and the Windows file path notation system is that you need to specify the
location of an element with a schema. As an example, consider the schema displayed in
Figure 26-4 on page 547. The root element is named Root , which has the subelement Supplier ,
which in turn has the subelement SupplierID . The XPath notation for the SupplierID
subelement is as follows:
/Root/Supplier/SupplierID
The Excel object model contains an XPath object with the properties and methods that
Excel needs to use XPath data in its operations. Table 26-4 lists the XPath object’s properties
and methods.
Search JabSto ::




Custom Search