How to Create XML File in a Few Simple Steps for Beginners

Dec 4, 2021

2 mins read

Published in
XML

Creating an XML file requires a basic understanding of XML and why it’s used in development.

These are 3 ways to create a new XML File.

  1. Gather all of the content items you want to include in your XML file.
  2. Use Text Editor to create the XML data structure.
  3. Validate the XML data which you have created.

What is an XML File?

XML file has valid XML data which can be parsed and utilized by the business logic or it can be shared to web services or the mobile application.

XML files can store information about the document, such as its structure and hierarchical relationships to other XML files which can be human-readable and machine-readable.

Step One: Gather all of the Content Items You Want to Include in Your XML File

To create an XML file first we need to gather all the data and what that data will be used for. i.e To represent the top 3 insurance companies in the USA, here is the sample XML data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8" ?>
<InsuranceCompanies>
    <Time>Dec 2021</Time>
    <Top_Ins_Companies>
        <No>1</No>
        <Name>Berkshire Hathaway ( BRK.A)</Name>
        <Market_Capitalization>$621 billion</Market_Capitalization>
    </Top_Ins_Companies>
    <Top_Ins_Companies>
        <No>2</No>
        <Name>China Life Insurance (LFC)</Name>
        <Market_Capitalization>$107 billion</Market_Capitalization>
    </Top_Ins_Companies>
    <Top_Ins_Companies>
        <No>3</No>
        <Name>Allianz (AZSEY) </Name>
        <Market_Capitalization>$91 billion</Market_Capitalization>
    </Top_Ins_Companies>
</InsuranceCompanies>

Step Two: Use Text Editor to create the XML data structure

Open Text Editor available in your system: Notepad, Notepad++, Sublime, Vim, or your preferred one.

Now start creating XML data in the Text Editor and save a file with the .xml extension. Here is the sample of XML for copy and paste.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8" ?>
<Movies>
    <Type>Action</Type>
    <movie>
        <No>1</No>
        <Name>IronMan</Name>
    </movie>
    <movie>
        <No>2</No>
        <Name>Mission Impossible</Name>
    </movie>
    <movie>
        <No>3</No>
        <Name>The Bourne Identity</Name>
    </movie>
</Movies>

Step Three: Validate the XML data which you have created.

Use an online XML Validator to validate xml data. Here is my preferred one and developed by us.

https://codebeautify.org/xmlvalidator

how to validate xml file
validate and create XML online

Bonus: Use this XML viewer to view and traverse XML in the tree structure

  1. https://codebeautify.org/xmlviewer

  2. https://jsonformatter.org/xml-viewer

  3. XML Formatter

Know More about XML :

Sharing is caring!