CSV files store data in comma separated values format. Data in CSV files is textual and tabled.
XML or Extensible Markup Language is also used to store structured data but the structure of the stored data could be more complex than a basic table. Thus, converting from CSV to XML is relatively straightforward since you will be converting data to a format which can store more complex structures.
For conversion we can assume that a XML file will represent CSV data as an <entry> tag, where each <entry> entity will be a CSV line. We will also assume that first line of CSV file contains field names and other lines contain data entries for these fields. Thus each entity in the XML Let’s proceed with an example of a CSV file.
Name Age Gender As a first step open this file in Microsoft Excel. You should get the following representation.
Now place the following formula in the column D starting from the second row:
You should get To make it fully compliant XML file add <entries> at the beginning and </entries> at the end of the file. Also, add the XML file header at the beginning as shown below.
You can run about XML file through XML beautifier online and get a better looking version as shown below.
Your XML file is ready!
John 30 Male
Melissa 25 Female
Alan 42 Male
Chelsey 40 Female
A B C 1 Name Age Gender 2 John 30 Male 3 Melissa 25 Female 4 Alan 42 Male 5 Chelsey 40 Female
=CONCAT("<entry><",A1, ">", A2, "</", A1, "><",B1, ">", B2, "</", B1, "><",C1, ">", C2, "</", C1, ">")
<entry><Name>John</Name><Age>30</Age><Gender>Male</Gender></CODE>
line as a result of this formula. Copy this formula to all the other rows in column D (to quickly copy it, select the D2 cell and click on a small rectangular section at the right bottom conrner of the cell border). Once you copy you will get following lines in column D.
<entry><Name>John</Name><Age>30</Age><Gender>Male</Gender></entry>
<entry><Name>Melissa</Name><Age>25</Age><Gender>Female</Gender></entry>
<entry><Name>Alan</Name><Age>42</Age><Gender>Male</Gender></entry>
<entry><Name>Chelsey</Name><Age>40</Age><Gender>Male</Gender></entry>
<?xml version="1.0" encoding="UTF-8"?>
<entries>
<entry><Name>John</Name><Age>30</Age><Gender>Male</Gender></entry>
<entry><Name>Melissa</Name><Age>25</Age><Gender>Female</Gender></entry>
<entry><Name>Alan</Name><Age>42</Age><Gender>Male</Gender></entry>
<entry><Name>Chelsey</Name><Age>40</Age><Gender>Male</Gender></entry>
</entries>
<?xml version="1.0" encoding="UTF-8"?>
<entries>
<entry>
<Name>John</Name>
<Age>30</Age>
<Gender>Male</Gender>
</entry>
<entry>
<Name>Melissa</Name>
<Age>25</Age>
<Gender>Female</Gender>
</entry>
<entry>
<Name>Alan</Name>
<Age>42</Age>
<Gender>Male</Gender>
</entry>
<entry>
<Name>Chelsey</Name>
<Age>40</Age>
<Gender>Male</Gender>
</entry>
</entries>
CSV Quick Info | |
---|---|
Comma Separaed Values | |
MIME Type | |
text/csv | |
Opens with | |
Microsoft Excel | |
Apple Numbers | |
Google Sheets | |
Microsoft Office Online |