Map and unmap XML elements Excel 2007

Author: mety Labels::

To import and export XML data files, you must create an XML map, and then map and unmap XML elements to cells to get the results that you want.

Locate XML Schema and XML data files

There are several ways to obtain XML Schema and XML data files.

Get the files from another database or application

Often, you have access to XML Schema (.xsd) (XML Schema: A formal specification, written in XML, that defines the structure of an XML document, including element names and rich data types, which elements can appear in combination, and which attributes are available for each element.) and XML data (.xml) files that were created in another database or application. For example, a line-of-business application may export data into XML file format, a commercial Web site or Web service may supply an XML file, or a customized application developed by your IT department may create an XML file as one of its functions.

Convert a text file

If you have a text file that you want to use, you can convert the text file to an XML file and then map it in Microsoft Office Excel 2007. For example, you can use Microsoft Office Access and Microsoft Office Excel to convert a text file to an XML file:

  1. Start Access.
  2. Create a linked table to the text file that you want to convert.
  3. Export the data from the linked table to an XML data file and an XML Schema file.
  4. Exit Access.
  5. Start Excel.
  6. Create an XML map based on the XSD file that you exported from Access. If the Multiple Roots dialog box appears, make sure that you choose dataroot to create an XML table. For more information,
  7. Create an XML table by mapping the dataroot element. For more information
  8. Import the XML file that you exported from Access. For more informationUse sample files

If you don't have convenient access to XML files, the following sample XML files contain basic XML elements and structures that you can use to test XML maps

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 attempt to infer one from an XML data file (.xsd).

  1. If the Developer tab is not available, do the following to display it:
    1. Click the Microsoft Office Button Button image, and then click Excel Options.
    2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

      Note The Ribbon is a component of the Microsoft Office Fluent user interface.

  2. On the Developer tab, in the XML group, click Source.

    XML group

    The XML Source task pane is displayed.

  3. Click XML Maps.
  4. Click Add.
  5. In the Look in list, click the drive, folder, or Internet location that contains the file that you want to open.
  6. Click the file, and then click Open. If you open:
    • An XML Schema file, XML creates an XML map based on the XML Schema.

      If the Multiple Roots dialog box appears, choose one of the root nodes that is defined in the XML Schema file.

    • An XML data file, Excel tries to infer the XML Schema from the XML data, and then creates an XML map.
  7. Click OK.

    The XML map is displayed in the XML Source task pane.

ShowIssue: When I add an XML map to my workbook, a message tells me that the XML Schema cannot be added to my workbook.

There are several types of XML Schema constructs that Excel does not support. The following list details the XML Schema constructs that cannot be imported into Excel:

<any> This element allows you to include elements that are not declared by the schema.

<anyAttribute> This element allows you to include attributes that are not 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 does not support recursive structures that are 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 that it is 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 does not support the simple content of the complex type but does support the child tags and attributes that are defined in that complex type.


Map XML elements

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

  1. If the Developer tab is not available, do the following to display it:
    1. Click the Microsoft Office Button Button image, and then click Excel Options.
    2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.
  2. On the Developer tab, in the XML group, click Source.

    XML group

    The XML Source task pane is displayed.

  3. To map one or more elements to your worksheet, select the elements in the XML Source task pane. To select nonadjacent elements, click one element, and then hold down CTRL and click each element that you want to map.
  4. To map the elements, do the following:
    1. Right-click the selected elements, and then click Map an element on the shortcut menu.
    2. In the Map XML elements dialog box, select a cell, and then 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 that the element is mapped.

  5. 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.

ShowIssue: All of the XML commands are dimmed, and I cannot map XML elements to any cells.

Check to see if the workbook is shared. (On the Review tab, in the Changes group, click Share Workbook.)

After you create a shared workbook, you can no longer map XML elements to any cells. If you want to map XML elements in a workbook that you want to share, you must map the XML elements to the cells that you want, import the XML data, remove all of the XML maps, and then create a shared workbook.


ShowIssue: I cannot copy an XML table to another workbook.

An XML table (which contains data) has an associated XML map (which defines the data structure). This XML map is stored in the workbook. However, when you copy an XML table to a new workbook, the XML map is not automatically included. So, instead of creating an XML table, an Excel table is created that contains the same data. If you want the new table to be created as an XML table, do the following:

  1. Add an XML map to the new workbook by using the .xml or .xsd file that you used to create the original XML map.

    Note 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.


ShowIssue: When I map a repeating element to a merged cell, Excel unmerges the cell.

Although you can map nonrepeating elements to a merged cell, you cannot map a repeating element to a merged cell. If you attempt to map a repeating element — or an element that contains a repeating element — to a merged cell, the cell is unmerged and the element is mapped to the cell where the pointer is located. This is the expected behavior, because repeating elements are designed to work only with unmerged cells.


Unmap XML elements

You unmap XML elements from a mapped cell or XML table because you decide not to use them, or because you don't want the contents of cells to be overwritten when you import XML data. For example, you may want to unmap an XML element if it is currently mapped to a single-mapped cell or repeating cells that contain formulas and you don't want to overwrite the formula when you import an XML file. After you import XML data, you can remap the XML element to the cells that contain the formulas, so that you can export the results of the formulas to the XML data file.

  1. If the Developer tab is not available, do the following to display it:
    1. Click the Microsoft Office Button Button image, and then click Excel Options.
    2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.
  2. On the Developer tab, in the XML group, click Source.

    XML group

    The XML Source task pane is displayed.

  3. Right-click the element name.
  4. Click Remove an element on the shortcut menu.

0 comments |

Labels

Blog Archive

Powered by Blogger.

I made these pages for me and my friends to help solving the problem we face regarding Computer & internet, if anyone wants me to answer a question or find out about some information please send me email and I will try to reply.*P.S. some of the article I wrote and the other I found on the internet I posted them in sprit of learning and shearing, please forgive me if you found something you don’t want to be in my blog, email me and I will delete them. Thank you for your interest in my pages.امل نجم Amal Nagm

banner 1 banner 2