Home > Article > Backend Development > Sample code detailing the XML reader
This chapter introduces various methods of viewing XML documents. XML documents can be viewed using a simple text editor or any browser. XML is supported by most major browsers. XML files can be opened in the browser by double-clicking the XML document (if it is a local file) or entering the URL path in the address bar (if the file is located on the server). You can also open other files in the browser in the same way. XML files are saved with the ".xml" extension.
Let's explore the various ways in which you can view XML files. The following example (sample.xml) applies to all chapters in this chapter.
<?xml version="1.0"?> <contact-info> <name>Tanmay Patil</name> <company>TutorialsPoint</company> <phone>(011) 123-4567</phone> </contact-info>
Text Editor
Any simple text editor such as Notepad, Textpad or TextEdit can be used to create or view an XML document, as shown below:
FireFox Browser
Double-click the file to open the above XML in FireFox, it will display the highlighted XML code, which makes the code more readable. It also displays a plus (+) and minus (-) sign to the left of the XML element. When we click on the minus sign (-) it hides the code and when we click on the plus sign (+) it expands the code. The output in FireFox will look like this:
Chrome Browser
Open the above XML code in Chrome browser. The code is displayed as follows:
Errors in the XML document
If some tags are missing in our XML code, the browser will display a information. We can try opening the following XML file in Chrome.
<?xml version="1.0"?> <contact-info> <name>Tanmay Patil</name> <company>TutorialsPoint</company> <phone>(011) 123-4567</phone> </ontact-info>
The opening and closing tags in the above code do not match (i.e. the _contactinfo tag), so the browser will display an error message as follows:
The above is the detailed content of Sample code detailing the XML reader. For more information, please follow other related articles on the PHP Chinese website!