Xml map in excel

To import and export XML data in Excel, an XML Map that associates XML elements with data in cells to get the results you want will be useful. To create one, you need to have an XML schema file (.xsd) and an XML data file (.xml). After creating the XML Map, you can map XML elements the way you want.

  • Locate or create XML schema and XML data files

  • Use sample XML schema and XML data files

  • Create an XML Map

  • Map XML elements

Locate or create XML schema and XML data files

If another database or application created an XML schema or XML data file, you might already have them available. For example, you might have a line-of-business application that exports data into these XML file formats, a commercial web site or web service that supplies these XML files, or a custom application developed by your IT department that automatically creates these XML files.

If you don’t have the necessary XML files, you can create them by saving the data you want to use as a text file. You can then use both Access and Excel to convert that text file to the XML files you need. Here’s how:

Access

  1. Import the text file you want to convert and link it to a new table.

    1. Click File > Open.

    2. In the Open dialog box, select and open the database in which you want to create a new table.

    3. Click External Data > Text File, and follow the instructions for each step, making sure that you link the table to the text file.

      Access creates the new table and displays it in the Navigation Pane.

  2. Export the data from the linked table to an XML data file and an XML schema file.

    1. Click External Data > XML File (in the Export group).

    2. In the Export — XML File dialog box, specify the file name and format, and click OK.

  3. Exit Access.

Excel

  1. Create an XML Map based on the XML schema file you exported from Access.

    If the Multiple Roots dialog box appears, make sure you choose dataroot so you can create an XML table.

  2. Create an XML table by mapping the dataroot element. See Map XML elements for more information.

  3. Import the XML file you exported from Access.

Notes: 

  • There are several types of XML schema element constructs Excel doesn’t support. The following XML schema element constructs can’t be imported into Excel:

  • <any>    This element allows you to include elements that aren’t declared by the schema.

  • <anyAttribute>    This element allows you to include attributes that aren’t declared by the schema.

  • Recursive structures    A common example of a recursive structure is a hierarchy of employees and managers in which the same XML elements are nested several levels. Excel doesn’t support recursive structures more than one level deep.

  • Abstract elements    These elements are meant to be declared in the schema, but never used as elements. Abstract elements depend on other elements being substituted for the abstract element.

  • Substitution groups    These groups allow an element to be swapped wherever another element is referenced. An element indicates it’s a member of another element’s substitution group through the <substitutionGroup> attribute.

  • Mixed content    This content is declared by using mixed=»true» on a complex type definition. Excel doesn’t support the simple content of the complex type but does support the child tags and attributes defined in that complex type.

Use sample XML schema and XML data files

The following sample data has basic XML elements and structures you can use to test XML mapping if you don’t have XML files or text files to create the XML files. Here’s how you can save this sample data to files on your computer:

  1. Select the sample text of the file you want to copy, and press Ctrl+C.

  2. Start Notepad, and press Ctrl+V to paste the sample text.

  3. Press Ctrl+S to save the file with the file name and extension of the sample data you copied.

  4. Press Ctrl+N in Notepad and repeat step 1-3 to create a file for the second sample text.

  5. Exit Notepad.

Sample XML data (Expenses.xml)

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Root>
  <EmployeeInfo>
    <Name>Jane Winston</Name>
    <Date>2001-01-01</Date>
    <Code>0001</Code>
  </EmployeeInfo>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Airfare</Description>
    <Amount>500.34</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Hotel</Description>
    <Amount>200</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Taxi Fare</Description>
    <Amount>100.00</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Long Distance Phone Charges</Description>
    <Amount>57.89</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Food</Description>
    <Amount>82.19</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-02</Date>
    <Description>Food</Description>
    <Amount>17.89</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-02</Date>
    <Description>Personal Items</Description>
    <Amount>32.54</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>Taxi Fare</Description>
    <Amount>75.00</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>Food</Description>
    <Amount>36.45</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>New Suit</Description>
    <Amount>750.00</Amount>
  </ExpenseItem>
</Root>

Sample XML schema (Expenses.xsd)

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="Root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element minOccurs="0" maxOccurs="1" name="EmployeeInfo">
          <xsd:complexType>
            <xsd:all>
              <xsd:element minOccurs="0" maxOccurs="1" name="Name" />
              <xsd:element minOccurs="0" maxOccurs="1" name="Date" />
              <xsd:element minOccurs="0" maxOccurs="1" name="Code" />
            </xsd:all>
          </xsd:complexType>
        </xsd:element>
        <xsd:element minOccurs="0" maxOccurs="unbounded" name="ExpenseItem">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Date" type="xsd:date"/>
              <xsd:element name="Description" type="xsd:string"/>
              <xsd:element name="Amount" type="xsd:decimal" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Create an XML Map

You create an XML Map by adding an XML schema to a workbook. The schema can be copied from an XML schema file (.xsd), or Excel can try to infer one from an XML data file (.xml).

  1. Click Developer > Source.

    XML commands on the Developer tab

    If you don’t see the Developer tab, see Show the Developer tab.

  2. In the XML Source task pane, click XML Maps, and then click Add.

  3. In the Look in list, click the drive, folder, or Internet location that contains the file you want to open.

  4. Click the file, and then click Open.

    • For an XML schema file, XML will create an XML Map based on the XML schema. If the Multiple Roots dialog box appears, choose one of the root nodes defined in the XML schema file.

    • For an XML data file, Excel will try to infer the XML schema from the XML data, and then creates an XML Map.

  5. Click OK.

    The XML Map appears in the XML Source task pane.

Map XML elements

You map XML elements to single-mapped cells and repeating cells in XML tables so you can create a relationship between the cell and the XML data element in the XML schema.

  1. Click Developer > Source.

    XML commands on the Developer tab

    If you don’t see the Developer tab, see Show the Developer tab.

  2. In the XML Source task pane, select the elements you want to map.

    To select nonadjacent elements, click one element, and then hold down Ctrl and click each element you want to map.

  3. To map the elements, do the following:

    1. Right-click the selected elements, and click Map element.

    2. In the Map XML elements dialog box, select a cell and click OK.

      Tip: You can also drag the selected elements to the worksheet location where you want them to appear.

      Each element appears in bold type in the XML Source task pane to indicate the element is mapped.

  4. Decide how you want handle labels and column headings:

    • When you drag a nonrepeating XML element onto the worksheet to create a single-mapped cell, a smart tag with three commands is displayed, which you can use to control the placement of the heading or label:

      My Data Already Has a Heading    Click this option to ignore the XML element heading, because the cell already has a heading (to the left of the data or above the data).

      Place XML Heading to the Left    Click this option to use the XML element heading as the cell label (to the left of the data).

      Place XML Heading Above    Click this option to use the XML element heading as the cell heading (above the data).

    • When you drag a repeating XML element onto the worksheet to create repeating cells in an XML table, the XML element names are automatically used as column headings for the table. However, you can change the column headings to any headings that you want by editing the column header cells.

      In the XML Source task pane, you can click Options to further control XML table behavior:

      Automatically Merge Elements When Mapping    When this check box is selected, XML tables are automatically expanded when you drag an element to a cell adjacent to the XML table.

      My Data Has Headings    When this check box is selected, existing data can be used as column headings when you map repeating elements to your worksheet.

      Notes: 

      • If all XML commands are dimmed, and you can’t map XML elements to any cells, the workbook might be shared. Click Review > Share Workbook to verify that and to remove it from shared use as needed.

        If you want to map XML elements in a workbook you want to share, map the XML elements to the cells you want, import the XML data, remove all of the XML maps, and then share the workbook.

      • If you can’t copy an XML table that contains data to another workbook, the XML table might have an associated XML Map that defines the data structure. This XML Map is stored in the workbook, but when you copy the XML table to a new workbook, the XML Map isn’t automatically included. Instead of copying the XML table, Excel creates an Excel table that contains the same data. If you want the new table to be an XML table, do the following:

        1. Add an XML Map to the new workbook by using the .xml or .xsd file you used to create the original XML Map. You should save these files if you want to add XML Maps to other workbooks.

        2. Map the XML elements to the table to make it an XML table.

      • When you map a repeating XML element to a merged cell, Excel unmerges the cell. This is expected behavior, because repeating elements are designed to work with unmerged cells only.

        You can map single, nonrepeating XML elements to a merged cell, but mapping a repeating XML element (or an element that contains a repeating element) to a merged cell isn’t allowed. The cell will be unmerged, and the element will be mapped to the cell where the pointer is located.

Tips: 

  • You can unmap XML elements you don’t want to use, or to prevent the contents of cells from being overwritten when you import XML data. For example, you could temporarily unmap an XML element from a single cell or repeating cells that have formulas you don’t want to overwrite when you import an XML file. When the import is complete, you can map the XML element to the formula cells again, so you can export the results of the formulas to the XML data file.

  • To unmap XML elements, right-click their name in the XML Source task pane, and click Remove element.

Show the Developer tab

If you don’t see the Developer tab, do the following to display it:

  • In Excel 2010 and newer versions:

    1. Click File > Options.

    2. Click the Customize Ribbon category.

    3. Under Main Tabs, check the Developer box, and click OK.

  • In Excel 2007:

    1. Click the Microsoft Office Button Office button image> Excel Options.

    2. Click the Popular category.

    3. Under Top options for working with Excel, check the Show Developer tab in the Ribbon box, and click OK.

See Also

Delete XML map information from a workbook

Append or overwrite mapped XML data

Overview of XML in Excel

Import XML data

Export XML data

Create an XML Map

  1. Click Developer > Source.
  2. In the XML Source task pane, click XML Maps, and then click Add.
  3. In the Look in list, click the drive, folder, or Internet location that contains the file you want to open.
  4. Click the file, and then click Open.
  5. Click OK.

Contents

  • 1 Where is XML Map in Excel?
  • 2 How do I get Excel data into XML?
  • 3 What is mapping XML?
  • 4 How do you create an XML file?
  • 5 What is XML data in Excel?
  • 6 How do I edit XML in Excel?
  • 7 How do I update the XML Map in Excel?
  • 8 How do I make an XML file?
  • 9 How do I create a simple XML file in Notepad?
  • 10 How do I format an XML file?
  • 11 How do I convert CSV to XML in Excel?
  • 12 Can Excel Open XML files?
  • 13 What is XML used for?
  • 14 How do I get XML data?
  • 15 What is XML vs HTML?
  • 16 How do I open XML files in Excel Windows 10?
  • 17 How do I create an XML File from Word?
  • 18 How create XML File in Intellij?
  • 19 How do I create an XML File in Visual Studio?
  • 20 How do I convert a large XML file to Excel?

Where is XML Map in Excel?

On the Developer tab, in the XML group, click Source. In the XML Source task pane, click XML Maps. The XML Maps dialog box is displayed.

How do I get Excel data into XML?

How to Import XML to Excel

  1. Step 1) Create a new workbook in Excel. Open a new workbook. Click on the DATA tab on the ribbon bar.
  2. Step 2) Select the XML as Data source. Then click on “From XML Data Import”
  3. Step 3) Locate and select the XML file. Now select the XML File to Excel sheet.

What is mapping XML?

Definition of XML Mapping. XML Mapping is defined as an editor used to map one or more XML Document to a common XML file by this, we can generate a transformation document after defining Mapping. Mapping does delete, editing or any persistent work.The mapping document is saved with the format classname.

How do you create an XML file?

Create an XML schema file to model your XML format data.
Procedure

  1. Click File > New > Other. A window opens in which you can select a wizard.
  2. Expand XML, select XML Schema File, click Next. The Create XML Schema wizard opens.
  3. Select a parent folder and enter a file name for your XML schema file.
  4. Click Finish.

What is XML data in Excel?

Excel has a defined XML schema that defines the contents of an Excel workbook, including XML tags that store all workbook information, such as data and properties, and define the overall structure of the workbook. Custom applications can use this Excel macro-enabled Office XML Format File.

How do I edit XML in Excel?

This can be accomplished a number of ways.

  1. Right click on the XML file and select Open with Microsoft Office Excel.
  2. Open Excel and drag and drop the XML file onto an empty workbook.
  3. Open Excel and use the File Open dialog box to select the XML File. You will need to change the file type to XML Files (*. xml).

How do I update the XML Map in Excel?

You cannot update them.
Each XML map can only be used in a list once in your workbook. There is a one-to-one relationship between the XML list, the XML Map and the data source. If you want to import multiple XML files into a single workbook you will need to use a different map (and list) for each file.

How do I make an XML file?

Use File -> New -> XML File. However, if you do not get the XML File option, then choose Other to locate XML File. When Select a Wizard dialog box opens, search for XML File and click Finish. Now a New XML File Wizard opens up.

How do I create a simple XML file in Notepad?

To create a well-formed XML document with XML Notepad, follow these steps:

  1. To open XML Notepad, click Start, point to Programs, point to XML Notepad, and then click Microsoft XML Notepad.
  2. Change Root_Element to Catalog and Child_Element to Book, and add an attribute and three child elements to the Book child element.

How do I format an XML file?

XML files are encoded in plaintext, so you can open them in any text editor and be able to clearly read it. Right-click the XML file and select “Open With.” This will display a list of programs to open the file in. Select “Notepad” (Windows) or “TextEdit” (Mac).

How do I convert CSV to XML in Excel?

Convert CSV to XML

  1. Step 1: Select your input. Enter Data.
  2. Step 2: Choose input options (optional) Input Options First row is column names.
  3. Step 3: Choose output options (optional) Output Options.
  4. Step 4: Create Custom Output via Template (optional)
  5. Step 5: Generate output.

Can Excel Open XML files?

The XML data is opened as read-only in Excel so that you don’t accidentally save your original source file in the Excel Macro-Enabled Workbook file format (. xlsm).

What is XML used for?

The Extensible Markup Language (XML) is a simple text-based format for representing structured information: documents, data, configuration, books, transactions, invoices, and much more. It was derived from an older standard format called SGML (ISO 8879), in order to be more suitable for Web use.

How do I get XML data?

We must have followed the process to read an XML file in Java:

  1. Instantiate XML file: DOM parser loads the XML file into memory and consider every tag as an element.
  2. Get root node: Document class provides the getDocumentElement() method to get the root node and the element of the XML file.

What is XML vs HTML?

HTML’s full form is Hypertext Markup Language, while XML is an Extensible Markup Language. The purpose of HTML is to display data and focus on how the data looks.
HTML vs XML: Key Differences.

HTML XML
Is a markup language. Is a standard markup language that defines other markup languages.

How do I open XML files in Excel Windows 10?

Replies (48) 

  1. Type Default programs in the search bar on Windows 10.
  2. Associate a file type or protocol with a program under Choose the program that Windows use by default in the Default Program Window.
  3. Select the . xml file type in the Associate a file type or protocol with a program Window and click on Ok.

How do I create an XML File from Word?

Click the Microsoft Office Button, and then click Save As. In the Save As dialog box, type My XML in the File name box, click Word XML Document in the Save as type list, and then click Save.

How create XML File in Intellij?

Right-click the directory and choose New | File on the context menu, or press Alt+Insert . In the New File dialog, specify the name of the new file with xml extension, for example, build. xml. The new file opens in the editor.

How do I create an XML File in Visual Studio?

To create a new XML Schema file

  1. In Visual Studio, open the File menu and select New > File. Or, use the Ctrl+N keyboard shortcut.
  2. In the New File dialog box, select XML Schema and then select Open. A new file is created. The Start View and an empty XML Schema Explorer window appear in Visual Studio.

How do I convert a large XML file to Excel?

How to convert XML to XLS

  1. Open free GroupDocs App website and choose GroupDocs.Conversion application.
  2. Click on Convert button. Your XML files will be uploaded and converted to XLS result format.
  3. You can also send a link to the XLS file to your email address.

Содержание

  1. Map XML elements to cells in an XML Map
  2. Locate or create XML schema and XML data files
  3. Use sample XML schema and XML data files
  4. Create an XML Map
  5. Map XML elements
  6. Show the Developer tab
  7. Overview of XML in Excel
  8. In this article
  9. Why use XML in Excel?
  10. XML data and schema files
  11. Key XML and Excel scenarios
  12. The basic process of using XML data in Excel
  13. Working with XML maps
  14. Using the XML Source task pane
  15. Element types and their icons
  16. Working with single-mapped cells
  17. Working with repeating cells in XML tables
  18. XML map security considerations
  19. Importing XML data
  20. Working with an inferred schema
  21. Exporting XML data
  22. Using the Excel Macro-enabled Office Open XML Format File
  23. Need more help?

Map XML elements to cells in an XML Map

To import and export XML data in Excel, an XML Map that associates XML elements with data in cells to get the results you want will be useful. To create one, you need to have an XML schema file (.xsd) and an XML data file (.xml). After creating the XML Map, you can map XML elements the way you want.

Tip: You’ll find more information about using XML with Excel in this overview of XML in Excel.

Locate or create XML schema and XML data files

If another database or application created an XML schema or XML data file, you might already have them available. For example, you might have a line-of-business application that exports data into these XML file formats, a commercial web site or web service that supplies these XML files, or a custom application developed by your IT department that automatically creates these XML files.

If you don’t have the necessary XML files, you can create them by saving the data you want to use as a text file. You can then use both Access and Excel to convert that text file to the XML files you need. Here’s how:

Import the text file you want to convert and link it to a new table.

Click File > Open.

In the Open dialog box, select and open the database in which you want to create a new table.

Click External Data > Text File, and follow the instructions for each step, making sure that you link the table to the text file.

Access creates the new table and displays it in the Navigation Pane.

Export the data from the linked table to an XML data file and an XML schema file.

Click External Data > XML File (in the Export group).

In the Export — XML File dialog box, specify the file name and format, and click OK.

Create an XML Map based on the XML schema file you exported from Access.

If the Multiple Roots dialog box appears, make sure you choose dataroot so you can create an XML table.

Create an XML table by mapping the dataroot element. See Map XML elements for more information.

Import the XML file you exported from Access.

There are several types of XML schema element constructs Excel doesn’t support. The following XML schema element constructs can’t be imported into Excel:

This element allows you to include elements that aren’t declared by the schema.

This element allows you to include attributes that aren’t declared by the schema.

Recursive structures A common example of a recursive structure is a hierarchy of employees and managers in which the same XML elements are nested several levels. Excel doesn’t support recursive structures more than one level deep.

Abstract elements These elements are meant to be declared in the schema, but never used as elements. Abstract elements depend on other elements being substituted for the abstract element.

Substitution groups These groups allow an element to be swapped wherever another element is referenced. An element indicates it’s a member of another element’s substitution group through the attribute.

Mixed content This content is declared by using mixed=»true» on a complex type definition. Excel doesn’t support the simple content of the complex type but does support the child tags and attributes defined in that complex type.

Use sample XML schema and XML data files

The following sample data has basic XML elements and structures you can use to test XML mapping if you don’t have XML files or text files to create the XML files. Here’s how you can save this sample data to files on your computer:

Select the sample text of the file you want to copy, and press Ctrl+C.

Start Notepad, and press Ctrl+V to paste the sample text.

Press Ctrl+S to save the file with the file name and extension of the sample data you copied.

Press Ctrl+N in Notepad and repeat step 1-3 to create a file for the second sample text.

Sample XML data (Expenses.xml)

Sample XML schema (Expenses.xsd)

Create an XML Map

You create an XML Map by adding an XML schema to a workbook. The schema can be copied from an XML schema file (.xsd), or Excel can try to infer one from an XML data file (.xml).

Click Developer > Source.

If you don’t see the Developer tab, see Show the Developer tab.

In the XML Source task pane, click XML Maps, and then click Add.

In the Look in list, click the drive, folder, or Internet location that contains the file you want to open.

Click the file, and then click Open.

For an XML schema file, XML will create an XML Map based on the XML schema. If the Multiple Roots dialog box appears, choose one of the root nodes defined in the XML schema file.

For an XML data file, Excel will try to infer the XML schema from the XML data, and then creates an XML Map.

The XML Map appears in the XML Source task pane.

Map XML elements

You map XML elements to single-mapped cells and repeating cells in XML tables so you can create a relationship between the cell and the XML data element in the XML schema.

Click Developer > Source.

If you don’t see the Developer tab, see Show the Developer tab.

In the XML Source task pane, select the elements you want to map.

To select nonadjacent elements, click one element, and then hold down Ctrl and click each element you want to map.

To map the elements, do the following:

Right-click the selected elements, and click Map element.

In the Map XML elements dialog box, select a cell and click OK.

Tip: You can also drag the selected elements to the worksheet location where you want them to appear.

Each element appears in bold type in the XML Source task pane to indicate the element is mapped.

Decide how you want handle labels and column headings:

When you drag a nonrepeating XML element onto the worksheet to create a single-mapped cell, a smart tag with three commands is displayed, which you can use to control the placement of the heading or label:

My Data Already Has a Heading Click this option to ignore the XML element heading, because the cell already has a heading (to the left of the data or above the data).

Place XML Heading to the Left Click this option to use the XML element heading as the cell label (to the left of the data).

Place XML Heading Above Click this option to use the XML element heading as the cell heading (above the data).

When you drag a repeating XML element onto the worksheet to create repeating cells in an XML table, the XML element names are automatically used as column headings for the table. However, you can change the column headings to any headings that you want by editing the column header cells.

In the XML Source task pane, you can click Options to further control XML table behavior:

Automatically Merge Elements When Mapping When this check box is selected, XML tables are automatically expanded when you drag an element to a cell adjacent to the XML table.

My Data Has Headings When this check box is selected, existing data can be used as column headings when you map repeating elements to your worksheet.

If all XML commands are dimmed, and you can’t map XML elements to any cells, the workbook might be shared. Click Review > Share Workbook to verify that and to remove it from shared use as needed.

If you want to map XML elements in a workbook you want to share, map the XML elements to the cells you want, import the XML data, remove all of the XML maps, and then share the workbook.

If you can’t copy an XML table that contains data to another workbook, the XML table might have an associated XML Map that defines the data structure. This XML Map is stored in the workbook, but when you copy the XML table to a new workbook, the XML Map isn’t automatically included. Instead of copying the XML table, Excel creates an Excel table that contains the same data. If you want the new table to be an XML table, do the following:

Add an XML Map to the new workbook by using the .xml or .xsd file you used to create the original XML Map. You should save these files if you want to add XML Maps to other workbooks.

Map the XML elements to the table to make it an XML table.

When you map a repeating XML element to a merged cell, Excel unmerges the cell. This is expected behavior, because repeating elements are designed to work with unmerged cells only.

You can map single, nonrepeating XML elements to a merged cell, but mapping a repeating XML element (or an element that contains a repeating element) to a merged cell isn’t allowed. The cell will be unmerged, and the element will be mapped to the cell where the pointer is located.

You can unmap XML elements you don’t want to use, or to prevent the contents of cells from being overwritten when you import XML data. For example, you could temporarily unmap an XML element from a single cell or repeating cells that have formulas you don’t want to overwrite when you import an XML file. When the import is complete, you can map the XML element to the formula cells again, so you can export the results of the formulas to the XML data file.

To unmap XML elements, right-click their name in the XML Source task pane, and click Remove element.

Show the Developer tab

If you don’t see the Developer tab, do the following to display it:

In Excel 2010 and newer versions:

Click File > Options.

Click the Customize Ribbon category.

Under Main Tabs, check the Developer box, and click OK.

Click the Microsoft Office Button > Excel Options.

Click the Popular category.

Under Top options for working with Excel, check the Show Developer tab in the Ribbon box, and click OK.

Источник

Overview of XML in Excel

Microsoft Excel makes it easy to import Extensible Markup Language (XML) data that is created from other databases and applications, to map XML elements from an XML schema to worksheet cells, and to export revised XML data for interaction with other databases and applications. Think of these XML features as turning Office Excel into an XML data file generator with a familiar user interface.

In this article

Why use XML in Excel?

XML is a technology that is designed for managing and sharing structured data in a human-readable text file. XML follows industry-standard guidelines and can be processed by a variety of databases and applications. Using XML, application designers can create their own customized tags, data structures, and schemas. In short, XML greatly eases the definition, transmission, validation, and interpretation of data between databases, applications, and organizations.

XML data and schema files

Excel works primarily with two types of XML files:

XML data files (.xml), which contain the custom tags and structured data.

Schema files (.xsd), which contain schema tags that enforce rules, such as data type and validation.

The XML standard also defines Extensible Stylesheet Language Transformation (XSLT) (.xslt) files, which are used to apply styles and transform XML data into different presentation formats. You can apply these transforms before you import XML files into Excel and after you export XML files from Excel. If XSLT files are linked to XML data files that you import into Excel, you do have the option to apply or not apply the formatting before the data is added to the worksheet, but only when you open an XML file by using the Open command from within Excel. Choose the XML Files (*.xml) file type before you click the Open button to see the XML files in the folder.

Key XML and Excel scenarios

By using XML and Excel, you can manage workbooks and data in ways that were previously impossible or very difficult. By using XML maps, you can easily add, identify, and extract specific pieces of business data from Excel documents. For example, an invoice that contains the name and address of a customer or a report that contains last quarter’s financial results are no longer just static reports. You can easily import this information from databases and applications, revise it, and export it to the same or other databases and applications.

The following are key scenarios that the XML features are designed to address:

Extend the functionality of existing Excel templates by mapping XML elements onto existing cells. This makes it easier to get XML data into and out of your templates without having to redesign them.

Use XML data as input to your existing calculation models by mapping XML elements onto existing worksheets.

Import XML data files into a new workbook.

Import XML data from a Web service into your Excel worksheet.

Export data in mapped cells to XML data files independent from other data in the workbook.

The basic process of using XML data in Excel

The following diagram shows how the different files and operations work together when you use XML with Excel. Essentially, there are five phases to the process:

Adding an XML schema file (.xsd) to a workbook

Mapping XML schema elements to individual cells or XML tables

Importing an XML data file (.xml) and binding the XML elements to mapped cells

Entering data, moving mapped cells, and leveraging Excel functionality, while preserving XML structure and definitions

Exporting revised data from mapped cells to an XML data file

Working with XML maps

You can create or open a workbook in Excel, attach an XML schema file (.xsd) to the workbook, and then use the XML Source task pane to map XML elements of the schema to individual cells or tables. After you map the XML elements to your worksheet, you can import and export XML data into and out of the mapped cells.

When you add an XML schema file (.xsd) to your workbook, you create an XML map. In general, XML maps are used to create mapped cells and to manage the relationship between mapped cells and individual elements in the XML schema. In addition, these XML maps are used to bind the contents of mapped cells to elements in the schema when you import or export XML data files (.xml).

There are two kinds of mapped cells that you can create: single-mapped cells and repeating cells (which appear as XML tables). To make designing your worksheet more flexible, you can drag the mapped cells anywhere on a worksheet and into any order — even one different from the XML schema. You can also choose which elements to map and not map.

The following rules about using XML maps are important to know:

A workbook can contain one or more XML maps.

You can only map one element to one location in a workbook at a time.

Each XML map is an independent entity, even if multiple XML maps in the same workbook refer to the same schema.

An XML map can only contain one root element. If you add a schema that defines more than one root element, you are prompted to choose the root element to use for the new XML map.

Using the XML Source task pane

You use the XML Source task pane to manage XML maps. To open it, on the Developer tab, in the XML group, click Source. The following diagram shows the main features of this task pane.

1. Lists XML maps that were added to the workbook

2. Displays a hierarchical list of XML elements in the currently listed XML map

3. Sets options when working with the XML Source task pane and the XML data, such as how to preview the data and control headings

4. Opens the XML Maps dialog box, which you can use to add, delete, or rename XML maps

5. Verifies whether you can export XML data through the current XML map

Element types and their icons

The following table summarizes each type of XML element that Excel can work with and the icon that is used to represent each type of element.

Required parent element

Repeating parent element

Required repeating parent element

Required child element

Repeating child element

Required repeating child element

Simple content in a complex structure

Required simple content in a complex structure

Working with single-mapped cells

A single-mapped cell is a cell that has been mapped to a nonrepeating XML element. You create a single-mapped cell by dragging a nonrepeating XML element from the XML Source task pane onto a single cell in your worksheet.

When you drag a nonrepeating XML element onto the worksheet, you can use a smart tag to choose to include the XML element name as a heading above or just to the left of the single-mapped cell, or you can use an existing cell value as a heading.

You can also use a formula in a single-mapped cell, if the cell is mapped to an XML element with an XML Schema Definition (XSD) data type that Excel interprets as a number, date, or time.

Working with repeating cells in XML tables

XML tables are similar in appearance and functionality to Excel tables. An XML table is an Excel table that has been mapped to one or more XML repeating elements. Each column in the XML table represents an XML element.

An XML table is created when you:

Use the Import command (in the XML group on the Developer tab) to import an XML data file.

Use the Open command from within Excel to open an XML data file — and then select As an XML table in the Open XML dialog box.

Use the From XML Data Import command (from the From Other Sources command button, in the Get External Data group, on the Data tab) to import an XML data file — and then select XML table in existing worksheet or New worksheet in the Import Data dialog box.

Drag one or more repeating elements from the XML Source task pane to a worksheet.

When you create an XML table, the XML element names are automatically used as column headings. You can change these to any column headings that you want. However, the original XML element names are always used when you export data from the mapped cells.

Two options under the Options button in the XML Source task pane are useful when you work with XML tables:

Automatically Merge Elements When Mapping When selected, Excel creates one XML table from multiple fields as they are dropped onto the worksheet. This option works as long as the multiple fields are dropped on the same row, one adjacent to the other. When this option is cleared, each element appears as its own XML table.

My Data Has Headings When selected, existing heading data is used as column headings for repeating elements that you map to your worksheet. When this option is cleared, the XML element names are used as column headings.

Using XML tables, you can easily import, export, sort, filter, and print data based on an XML data source. However, XML tables do have some limitations regarding how they can be arranged on the worksheet.

XML tables are row-based, meaning that they grow from the header row down. You cannot add new entries above existing rows.

You cannot transpose an XML table so that new entries will be added to the right.

You can use formulas in columns that are mapped to XML elements with an XML Schema Definition (XSD) data type that Excel interprets as a number, date, or time. Just as in an Excel table, formulas in an XML table are filled down the column when new rows are added to the table.

XML map security considerations

An XML map and its data source information are saved with the Excel workbook, not a specific worksheet. A malicious user can view this map information by using a Microsoft Visual Basic for Applications (VBA) macro. Furthermore, if you save your workbook as a macro-enabled Excel Office Open XML Format File, this map information can be viewed through Microsoft Notepad or through another text-editing program.

If you want to keep using the map information but remove the potentially sensitive data source information, you can delete the data source definition of the XML schema from the workbook, but still export the XML data, by clearing the Save data source definition in workbook check box in the XML Map Properties dialog box, which is available from the Map Properties command in the XML group on the Developer tab.

If you delete a worksheet before you delete a map, the map information about the data sources, and possibly other sensitive information, is still saved in the workbook. If you are updating the workbook to remove sensitive information, make sure that you delete the XML map before you delete the worksheet, so that the map information is permanently removed from the workbook.

Importing XML data

You can import XML data into an existing XML map in your workbook. When you import data, you bind the data from the file to an XML map that is stored in your workbook. This means that each data element in the XML data file has a corresponding element, in the XML schema, that you mapped from an XML Schema file or inferred schema. Each XML map can only have one XML data binding, and an XML data binding is bound to all of the mappings that were created from a single XML map.

You can display the XML Map Properties dialog box (Click Map Properties in the XML group on the Developer tab.), which has three options, all selected by default, that you can set or clear to control the behavior of an XML data binding:

Validate data against schema for import and export Specifies whether Excel validates data against the XML map when importing data. Click this option when you want to ensure that the XML data that you import conforms to the XML schema.

Overwrite existing data with new data Specifies whether data is overwritten when you import data. Click this option when you want to replace the current data with new data, for example, when up-to-date data is contained in the new XML data file.

Append new data to existing XML tables Specifies whether the contents of the data source are appended to the existing data on the worksheet. Click this option, for example, when you are consolidating data from several similar XML data files into an XML table, or you do not want to overwrite the contents of a cell that contains a function.

When you import XML data, you may want to overwrite some mapped cells but not others. For example, some mapped cells may contain formulas and you don’t want to overwrite the formula when you import an XML file. There are two approaches that you can take:

Unmap the elements that you don’t want overwritten, before you import the XML data. After you import the XML data, you can remap the XML element to the cells containing the formulas, so that you can export the results of the formulas to the XML data file.

Create two XML maps from the same XML schema. Use one XML map for importing the XML data. In this «Import» XML map, don’t map elements to the cells that contain formulas or other data that you don’t want overwritten. Use another XML map for exporting the data. In this «Export» XML map, map the elements that you want to export to an XML file.

Note: The ability to import XML data from a Web service by using a Data Retrieval Service Connection (.uxdc) file to connect to a data source is no longer supported in versions later than Excel 2003 through the user interface. If you open a workbook that was created in Excel 2003, you can still view the data, but you cannot edit or refresh the source data.

Working with an inferred schema

If you import XML data without first adding a corresponding XML schema to create an XML map, Excel tries to infer a schema for you based on the tags that are defined in the XML data file. The inferred schema is stored with the workbook, and the inferred schema allows you to work with XML data if an XML schema file isn’t associated with the workbook.

When you work with imported XML data that has an inferred schema, you can also customize the XML Source task pane. Select the Preview Data in Task Pane option from the Options button to display the first row of data as sample data in the element list, if you imported XML data associated with the XML map in the current session of Excel.

You cannot export the Excel inferred schema as a separate XML schema data file (.xsd). Although there are XML schema editors and other methods for creating an XML schema file, you may not have convenient access to them or know how to use them. As an alternative, you can use the Excel 2003 XML Tools Add-in Version 1.1, which can create a schema file from an XML map. For more information, see Using the Excel 2003 XML Tools Add-in Version 1.1.

Exporting XML data

You export XML data by exporting the contents of mapped cells on the worksheet. When you export data, Excel applies the following rules to determine what data to save and how to save it:

Empty items are not created when blank cells exist for an optional element, but empty items are created when blank cells exist for a required element.

Unicode Transformation Format-8 (UTF-8) encoding is used to write the data.

All namespaces are defined in the Root XML element.

Excel overwrites existing namespace prefixes. The default namespace is assigned a prefix of ns0. Successive namespaces are designated ns1, ns2 to ns where is the number of namespaces written to the XML file.

Comment nodes are not preserved.

You can display the XML Map Properties dialog box (Click Map Properties in the XML group on the Developer tab.) and then use the Validate data against schema for import and export option (active by default) to specify whether Excel validates data against the XML map when exporting data. Click this option when you want to ensure that the XML data you export conforms to the XML schema.

Using the Excel Macro-enabled Office Open XML Format File

You can save an Excel workbook in a variety of file formats, including the Excel macro-enabled Office Open XML Format File (.xlsm). Excel has a defined XML schema that defines the contents of an Excel workbook, including XML tags that store all workbook information, such as data and properties, and define the overall structure of the workbook. Custom applications can use this Excel macro-enabled Office XML Format File. For example, developers may want to create a custom application to search for data in multiple workbooks that are saved in the this format and create a reporting system based on the data found.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

There are 2 sources for XML maps I know of:

1.You have a copy of the XML data you wish to map (XML file)
2.You know the location of the XML’s schema (XSD file)

In both cases, it’s simply a matter of pointing Excel to either location. In the first case Excel guesses at the Map, in the latter it uses the data in the Schema to create the map.

For this example lets assume we want to Create a Map for the XML data returned from the Yahoo Web Search Service.

This is a good example to demonstrate each method becuase they have a sample of the XML data available, and they also have the Schema available, and both work to create the Map.

Note: Keep in mind the XML or XSD files need not be at a url address, they can be saved on your local drive.

Create a Map in Excel
1. On the main menu goto Data->XML->XML Source
2. Click the XML Maps Button
xml map

3. In the newly opened dialog box click the Add button
add xml map

4. Enter the location of the XSD or XML file you wish to Map
xml map location

Note: If you are trying to paste the URL into the File Name box, you can’t right click in the box, you must use the paste shortcut (Ctrl-V)

5. Click the OPEN button.

That’s it, you should have an XML Map in your workbook based on the XML or XSD file you designated. Here’s what the map I just added looks like:
xml map final

Microsoft Excel is a useful instrument for organizing and structuring very different data. It can be used to process information by various methods and edit data arrays.

Let us see its tools for generation and processing web applications files. Using a particular example, we will learn the basics of work with XML in Excel.



How to create XML-file in Excel

XML is a file standard for transferring files over the Internet. Excel supports its export and import.

We are going to look through the process of creation an XML-file using factory calendar as a particular example.

  1. Create a table on which you want to create an XML file in Excel and fill it with data.
  2. Create and insert a map with the required XML document structure.
  3. Export the table data in XML format.

Altogether.

  1. Our table is a Holiday calendar.
  2. Fill the table.

  3. Create any text editor (such as «Notepad») the desired XML structure to generate a map file is saved. In this example, use the map structure:
  4. Open the tool «DEVELOPER». Choose the dialog box «Source» in the XML tab.
  5. Fill the table.

  6. If Excel cannot see XML maps, they have to be added. Press «XML Maps» button.
  7. Fill the table.

  8. Press «Add». Find your XML file – press ОК.
  9. Fill the table.

  10. Elements of the schema will appear in the right column. They have to be dragged to the corresponding column names of the table.
  11. Fill the table.

  12. Check whether the export is possible.
  13. Fill the table.

  14. When all of the elements will be associated, right click any cell on the table and choose XML – Export.

Fill the table.

Save the file.

How to save an Excel file in XML format

One of the options:

  1. Press CTRL+S, choose «Save as» — «Other formats».
  2. Set the name. Choose the file destination and type – XML.

Press «Save» button.

If you get any errors, try to save the workbook as XML 2003 table or web page. Usually, there are no problems with these formats.

Other options:

  1. Download XLC to XML converter, or find a service, which exports files online.
  2. Download XML Tools Add-in from the official Microsoft web site. It is available free of charge.
  3. Open a new workbook. Press CTRL+O «Open».

How to open an XML file in Excel

  1. Change the format to XML file. Choose the desired file. Press CTRL+O.
  2. Open it as an XML-table. Press OK.
  3. Fill the table.

  4. Similar notification will appear.
  5. Fill the table.

  6. Press OK. You can work with this table the same way as with any Excel file.

Fill the table.

How to convert XML file to Excel

  1. Open the tool «DEVELOPER». Choose the dialog box «Import».
  2. Fill the table.

  3. Choose a file in the dialog box, that you want to convert.
  4. Press «Import». Excel will offer to create a scheme automatically based on the data received. Press OK. A window will open, where you will need to choose a destination for the importing file.
  5. Fill the table.

  6. Set the range for import. It is better to add extra cells for future entries. Press «OK».

Fill the table.

From now on, the created table is being edited and saved in Excel format.

How to collect data from XML-files to Excel

The principle of collecting data from several XML-files is the same as the principle of conversion. When we import data to Excel, the XML map transfers at the same time. You can also transfer other data in this schema.

Each new file will be linked to the existing map. Every element of the table structure binds to an element from XML map. Only one data link is allowed.

In order to configure binding settings, in the «DEVELOPER» menu choose the «Map Proparties» instrument.

Fill the table.

Features:

  1. Excel will check every new file for compliance with the existing map (if you check the box next to this line).
  2. The data can be update. Also, new information can be added to the existing table (it makes sense, if you need to collect data from similar files).

Other ways to get structure data (schema):

  1. Download it from a database of a specialized business application. Commercial sites and services may provide schemas. Simple options are in the public domain.
  2. Use prepared examples in order to validate the maps. Examples contain the basic elements and structure data. Copy and paste it into the program «Notepad» – and save it with the desired extension.

These are all manual methods of import and export files structure data.

In this tutorial we’ll discuss how to export your worksheet data as an XML file. The first method is, click File > Save As > Browse and from Save As dialog box select the XML Data (*.xml) in the Save as type. The second method is, click Developer > Export. To import and export XML data, Excel required at least one XML map (XML schema .xsd file) attached to the workbook. Click Developer > Source and then use the XML Source task pane to attach schema files and map XML elements of the schema to individual cells or tables.

  • This tutorial covers the following topics:
  • Creating XML Maps
  • Save workbook as XML Data to export its data
  • Export XML data using Developer > Export
  • Creating the XML Schema File
  • Errors while exporting data to XML file
    • Export button is disabled
    • The XML maps in this workbook are not exportable
    • Workbook does not contain any XML mappings
    • I don’t have XML schema (.xsd extension) file

XML Maps

XML schemas in Excel are called XML maps. You can associate single or multiple schemas with a workbook and then map the schema elements to cells on the worksheet. To create XML map, open the XML Source task pane by clicking the Developer > Source. (If you don’t see the Developer tab, see Show the Developer tab.)
Source button to open XML Source task pane

Excel displays the XML Source task pane. The XML Source task pane is blank because the current worksheet doesn’t have any XML maps associated with it:
Blank XML Source task pane

The XML Source task pane is used for displaying XML maps found in the XML data or schema documents, and mapping XML elements to cells or ranges on a worksheet. In the XML Source task pane, click the XML Maps button to open the XML Maps dialog box as shown in following figure:
XML Maps Dialog Box

The XML Maps dialog box is used to add, delete, or rename an XML map associated with the workbook. Click the Add button and select an XML schema (.xsd extension) file and click Open:
Select XML Source Dialog Box

If the XML schema file have more than one root node, the Multiple Roots dialog box appears and you must select a root node which you wan to use. The map.xsd file has a single root node so the Multiple Roots dialog box will not appear.

Excel displays the XML map name (root element name is small letters) in the XML Maps dialog box shown in following figure, click OK to return to Excel window:
XML Maps dialog box

The XML Source task pane now displays the structure of the XML map:
XML Source task pane showing map structure

To create the XML table, place all of the XML elements on the worksheet by dragging the root element pets from the XML Source pane and dropping it on a cell on the sheet:
Drag and drop xml elements

To add rows in XML table, move mouse pointer to bottom-right corner of the table, click and hold the mouse button when double headed arrows appears, drag the pointer to downside and drop pointer at desired cell:
Expand xml table

The XML table is mapped to the Excel cells. Fill all rows and try to export the table or workbook as an XML document using one of the following methods.

Save workbook as XML Data to export its data

Click File > Save As > Browse and select the location where you want to save the XML file. Write a file name for you XML file in File name field and select XML Data (*.xml) from the Save as type list, as shown in following figure:
Save As dialog box

Export XML from the Developer tab

To export XML data, click any cell in the XML table and then, on the Developer tab, click the Export button to display the Export XML dialog box:
Developer Export button

Navigate to the folder in which you want to export your data, enter a name for the file and click Export:
Exprt XML dialog box

Creating an XML Map (Schema)

An XML map is actually an XML schema (plain text document) which helps the other application to understand the elements in the XML document. Excel allows you to add multiple XML maps to a workbook. If you want to create XML schema used in this tutorials, open a text editor, copy following code, and paste into the text editor and save it as map.xsd:

<?xml version="1.0" encoding="utf-8"?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="pets">
   <xs:complexType>
    <xs:sequence>
     <xs:element maxOccurs="unbounded" name="Pet">
      <xs:complexType>
       <xs:simpleContent>
        <xs:extension base="xs:string">
         <xs:attribute name="Type" type="xs:string" />
         <xs:attribute name="Age" type="xs:integer" />
        </xs:extension>
       </xs:simpleContent>
      </xs:complexType>
     </xs:element>
    </xs:sequence>
   </xs:complexType>
  </xs:element>
 </xs:schema>

The map.xsd XML scheme (map) defines the elements of the pets XML. Read the full tutorial on XML schema: Creating XML Schema.

Errors when export data as XML

  1. Developer Tab > Export button is disabled
    Export button greyed out

    Solutions: This error occurs because an XML map is not yet added. Open XML Source task pane by clicking the Developer > Source and click XML maps button from the XML Source task pane to add XML maps. After adding the XML map, select the elements or entire nodes in the XML map and drag them onto the worksheet.

  2. Cannot save or export XML data. The XML maps in this workbook are not exportable:

    Solution: This error occurs because an XML map is not yet applied. Open XML Source task pane by clicking the Developer > Source and select the elements or entire nodes in the XML map and drag them onto the worksheet.

  3. Can not save XML data because the workbook does not contain any XML mappings:
    Workbook does not contain any XML mappings

    This problem occurs when you try to specify “XML Data (.xml)” in the “Save as type” list.

    Solutions: This error occurs because an XML map is not yet applied. Open XML Source task pane by clicking the Developer > Source and select the elements or entire nodes in the XML map and drag them onto the worksheet. If the XML Source task pane is blank, click XML maps button from the XML Source task pane to add XML maps.

  4. I don’t have XML schema (.xsd extension) file to create an XML map

    Solution: If you don’t have an XML schema (.xsd extension) file but you’ve a sample XML data file then you can use this sample XML file to create an XML map. For example, you can use pets.xml file, created in Introducing XML tutorial:

    Open XML Source task pane by clicking the Developer > Source and click XML maps button from the XML Source task pane to add XML maps. The XML Maps dialog appears, click Add, select pets.xml file and click Open. Excel will automatically creates a schema based on the source data:
    Excel creates schema based on data

    Click Ok to create the map.

When you export data to an XML file, the two XML events AfterXMLExport and BeforeXMLExport triggered. You can write Workbook_AfterXMLExport and Workbook_BeforeXMLExport event listener procedures for these events to control what happens before and after import.

by updated Aug 05, 2020

Like this post? Please share to your friends:
  • Xml in excel cell
  • Xml from xsd excel
  • Xml from excel vba
  • Xml from excel sheet
  • Xml from excel 2007