Excel Open XML File
Data may come in different ways and the source file varies from one situation to another. Data is the most important part to make decisions but it is important to know how we can import data from different sources. Common file extensions we are all familiar with are “Text file and Excel file” but there are several other sources available as well. In this article, we will show you how to open excel data into XML format and also how to import XML data into excel with neat formatting.
What is XML File?
Extensible Markup Language of storing data in the XML format. With excel data we can convert the data into XML format, like all the other external database rules XML too has its own standard set of actions.
The following are the rules of the XML file.
- The first line of the data should always include the below line of code.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- XML format has head and tail of the table name.
<TableName> Column1<Value>Column1 Column2<Value>Column2 <TableName> <TableName> Column1<Value>Column1 Column2<Value>Column2 <TableName>
Like this, we can create XML table to convert the excel data into XML table format. Now we will see how to open excel data into XML format.
Example of Converting Excel Data to XML File Format
For example, look at the below data in excel worksheet.
We need to convert this into an XML excel format like the below one.
Here what we need to do is create two sample lines format for our data. As we have discussed our rules to create a mandatory line of code is below.
<?xml version=”1.0″ encoding=”UTF-8″?>
Next, we need to enter the table name as per our wish and the table name is <EmpRecord>
After the table name, we need to enter the column header name and that is <FirstName> next we need to include the name and end this with column header again.
Like this, we need to prepare a schema of XML data. For the above data, I have created the schema, you can copy and paste the schema.
<?xml version="1.0" encoding="UTF-8"?> <dataset> <EmpRecord> <FirstName>James</FirstName> <LastName>Butt</LastName> <City>New Orleans</City> <Country>Orleans</Country> </EmpRecord> <EmpRecord> <FirstName>Josephine</FirstName> <LastName>Darakjy</LastName> <City>Brighton</City> <Country>Livingston</Country> </EmpRecord> </dataset>
We have created two samples, so by using this we can apply the same schema to our excel file and extract data in the same format (XML) as provided above.
Copy the above code to a Text file and save the file as “XML”.
Follow the below steps to open the excel data into XML format.
Step 1: In the data workbook, go to the “Developer” tab and click on “Source”.
Step 2: This will open up below the “XML Source” window to the right of the worksheet and click on “XML Maps”.
Step 3: Now this will open up the XML Maps window then click on the “Add” button to choose the XML schema file.
Step 4: Now choose the already saved XML file with the schema.
Step 5: Click on “Open” and it will ask your confirmation.
Step 6: Click on “Ok” two more times to get the schema headers to the left.
Step 7: Now drag and drop the first column header “FirstName” from the XML source to the actual table in the worksheet.
This will apply the “FirstName” column schema to the data table column.
Now repeat the same for remaining columns as well. Drag and drop respective schema columns to respective columns of the data table.
So now all the XML schema columns are applied. Now under the Developer tab excel click on the “Export” option.
Now this will ask you to save the file in the desired folder, give a name and save the file.
After choosing the folder click on “Export” and your data will be extracted as the “XML Data” file.
Now open the file and all the rows are in the XML format now.
Like this, we can extract or open the excel data to the XML file.
Import XML Data into Excel
Importing XML file to excel requires to follow certain steps. Follow the below steps to import data from an XML file.
Step 1: Under the Data tab click on “Get Data & From File”, choose From XML.
Step 2: This will ask you to choose the file from the stored location. Choose the file.
Step 3: Click on “Import” and your data will be imported to excel file.
Like this, we can work with “XML Files” in excel.
Things to Remember
- XML file follows certain script so you need to follow a mandatory line of codes as provided above.
- When you XML file it will open with TEXT File only but the format is in XML Schema.
- We need to create at least two schema examples to apply the same logic to whole data and export as an XML file.
This has been a guide to Excel Open XML. Here we discuss how to export excel data into XML format and also how to import XML data into excel. You may learn more about excel from the following articles –