How to Create xml File

How to Create an XML File

Creating an XML file is simple, and you don’t need advanced software to start—just a basic text editor like Notepad, VS Code, or Sublime Text. XML (eXtensible Markup Language) is designed to store and transport data in a structured, human-readable way.

1. Open Your Text Editor

Open your preferred text editor. This could be Notepad (Windows), Sublime Text, VS Code, or any editor that lets you save files with the .xml extension.

2. Start with the XML Declaration

At the very top of your file, add the XML declaration. It tells parsers that the file uses XML:

xml
<?xml version="1.0" encoding="UTF-8"?>

This line is important for most XML files.

3. Create a Root Element

Every XML file must have a root element. This element will wrap around all other content:

xml
<root> </root>

Replace “root” with a name relevant to your data (e.g., <catalog><person><data>, etc.).

4. Add Child Elements

Inside your root element, add child elements. For example:

xml
<catalog> <book> <title>XML Developer's Guide</title> <author>Gambardella, Matthew</author> <genre>Computer</genre> </book> </catalog>

You can nest child elements to represent a hierarchy as needed.

5. Validate Your XML

Double-check that:

  • All tags are properly opened and closed,

  • There are no missing angle brackets,

  • There are no syntax errors,

  • Only one root element exists.

6. Save the File

Save your file with a .xml extension. For example: mydata.xml.

7. Test Your XML File

You can open your XML file in any browser (like Chrome, Edge, or Firefox) to make sure it displays without errors. Browsers will show an error if the XML is not well-formed.


Quick Example

xml
<?xml version="1.0" encoding="UTF-8"?> <students> <student> <name>Ali</name> <roll>101</roll> </student> <student> <name>Sara</name> <roll>102</roll> </student> </students>

This structure can be customized as per your data requirements.


XML creation is that simple no complex tools required, just clear markup and attention to detail.

Scroll to Top