How to Create an .Xml File

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Image Credit: Stockbyte/Stockbyte/Getty Images

XML stands for Extensible Markup Language. This form of computer programming transports and stores data as a text file but does not display it. For the data to display, XML must work in conjunction with another language such as PHP, JavaScript or HTML. Data, stored in a tree structure, uses elements designed and named by the person writing the document. Writing data into an XML file is a straightforward process that just about anyone can master with a little practice.

Advertisement

Step 1

Open a text editor. To write XML documents you can use a standard text editor such as Notepad. Click on the "Start" button located at the bottom of your desktop. Select "All Programs," then "Accessories." Click on "Notepad" to open the program.

Video of the Day

Step 2

Make your declaration at the top of the page. An XML declaration gives the program running your page instructions. A standard declaration starts with <?xml, lists the version and ends with a closing tag. An example of a declaration might look something like this:

Advertisement

The declaration should always be the first line of any XML document.

Step 3

Set up your tree structure with a root element and child elements. The tree structure is the heart of the XML language. A root element is the first line of your tree and it defines or names the data stream you are writing. For instance, you might want to name the category of a product like music as your root element. To do this, your first line would be . The < tells the program you are naming an element. The fact that it is the first item makes it the root. Child elements provide details of the root. Using this example, a child element might be and would be listed underneath the root. All elements require opening and closing tags. A closing tag tells the program you are done with a particular element. The closing tag for music would look like . The closing tag falls at the end of each element. As is a child of , it would be located between the two tags:

Advertisement

Advertisement

Step 4

Check your tree for any errors, such as missing tags. Remember, all elements must have a closing tag.

Step 5

Save your file in the XML format by using .xml as the extension. In most programs, this means clicking on "File" located in the software menu at the top of the screen. Select "File," then "Save As." Type in a name for the file and end it with .xml. The document will save to your hard drive as an XML file. For instance, a music catalog created in XML might be "music.xml."

Video of the Day

Advertisement

Advertisement

references

Report an Issue

screenshot of the current page

Screenshot loading...