Creating an XML Mapping Schema in Excel
Creating an XML Mapping Schema in Excel
Getting Started with Excel 2010 Extensibility: Learn how to create and utilize Xml Mapping schemas in Excel 2010.
In this exercise, you create a sample XML data file. You then create an XML Mapping schema by using one of two methods. You then use that schema to create a table mapped to the sam
task, you must do the following:
XML
<?xml version='1.0'?>
<BookInfo>
<Book>
<ISBN>989-0-487-04641-2</ISBN>
<Title>My World</Title>
<Author>Nancy Davolio</Author>
<Quantity>121</Quantity>
</Book>
<Book>
<ISBN>981-0-776-05541-0</ISBN>
<Title>Get Connected</Title>
<Author>Janet Leverling</Author>
<Quantity>435</Quantity>
</Book>
<Book>
<ISBN>999-1-543-02345-2</ISBN>
<Title>Honesty</Title>
<Author>Robert Fuller</Author>
<Quantity>315</Quantity>
</Book>
</BookInfo>
To create the XSD in Excel by explicitly writing the XML in the code
VBA
Sub Create_XSD()
Dim StrMyXml As String, MyMap As XmlMap
Dim StrMySchema As String
StrMyXml = "< BookInfo >" this code has error
StrMyXml = StrMyXml & "<Book>"
StrMyXml = StrMyXml & "<ISBN>Text</ISBN>"
StrMyXml = StrMyXml & "<Title>Text</Title>"
StrMyXml = StrMyXml & "<Author>Text</Author>"
StrMyXml = StrMyXml & "<Quantity>999</Quantity>"
StrMyXml = StrMyXml & "</Book>"
StrMyXml = StrMyXml & "<Book></Book>"
StrMyXml = StrMyXml & "</ BookInfo >"
6. Next, run the code. On the Developer tab, click Macros, highlight Create_XSD, and then click Run. Examine the schema file at C:\MySchema.xsd. Shortly, you will load this file int
To create the schema in Excel by reading the XML data into a string
1. In a blank Excel 2010 workbook, open the Visual Basic Editor by pressing Alt+F11.
VBA
Sub Create_XSD2()
Dim StrMyXml As String, MyMap As XmlMap change to D:
Dim StrMySchema As String
' Book.xml is the file created in section one of this topic.
StrMyXml = "C:\BookData.xml"
https://msdn.microsoft.com/en-us/library/office/gg469857(v=office.14).aspx 2/3
8/20/2017 Creating an XML Mapping Schema in Excel 2010 should be Create_XSD2
5. Next, run the code. On the Developers tab, click Macros, highlight Create_XSD, and then click Run. Examine the schema file at C:\MySchema.xsd. Shortly, you will load this file in
map.
if no developer, file ->
no need in options -> customise ribbon
new version -> click developer -> ok
Import the Schema and XML Data into Excel
no need for
In this task, you import the schema created in the previous section into Excel to create an XML map and then import an XML data file.
steps 2/3 if
To create the Xml Map and then import the XML data file into Excel bookinfo is
1. On the Developer tab, in the XML group, click Source to open the XML Source task pane.
already
there
2. On the task pane, click Xml Maps.
3. In the Xml Maps dialog box, click Add, navigate to the file BookInfo.xsd, click Open, and then click OK.
4. In the XML Source task pane, drag the BookInfo node to cell A1. This action creates a table in the worksheet as shown in Figure 1. You can format the table as necessary.
5. Next, import the XML data file. On the Developer tab, click Import.
6. In the Import XML dialog box, navigate to the XML data file and then click Import. The data is mapped into the formatted table as shown in Figure 2.
Next Steps
https://msdn.microsoft.com/en-us/library/office/ff936211(v=office.14).aspx#NextSteps
https://msdn.microsoft.com/en-us/library/office/ff936211(v=office.14).aspx#AdditionalResources
© 2017 Microsoft
https://msdn.microsoft.com/en-us/library/office/gg469857(v=office.14).aspx 3/3