XML - Viewers


Advertisements


This chapter describes THE various methods to view an XML document. An XML document can be viewed using a simple text editor or any browser. Most of the major browsers supports XML. XML files can be opened in the browser by just double-clicking the XML document (if it is a local file) or by typing the URL path in the address bar (if the file is located on the server), in the same way as we open other files in the browser. XML files are saved with a ".xml" extension.

Let us explore various methods by which we can view an XML file. Following example (sample.xml) is used to view all the sections of this chapter.

<?xml version = "1.0"?>
<contact-info>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>

Text Editors

Any simple text editor such as Notepad, TextPad, or TextEdit can be used to create or view an XML document as shown below −

View XML In Notepad

Firefox Browser

Open the above XML code in Chrome by double-clicking the file. The XML code displays coding with color, which makes the code readable. It shows plus(+) or minus (-) sign at the left side in the XML element. When we click the minus sign (-), the code hides. When we click the plus (+) sign, the code lines get expanded. The output in Firefox is as shown below −

View XML In Firefox

Chrome Browser

Open the above XML code in Chrome browser. The code gets displayed as shown below −

View XML In Chrome

Errors in XML Document

If your XML code has some tags missing, then a message is displayed in the browser. Let us try to open the following XML file in Chrome −

<?xml version = "1.0"?>
<contact-info>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>

In the above code, the start and end tags are not matching (refer the contact_info tag), hence an error message is displayed by the browser as shown below −

View XML Error

Advertisements
E-Books Store