Home > Backend Development > XML/RSS Tutorial > Sample code detailing the XML reader

Sample code detailing the XML reader

黄舟
Release: 2017-03-20 16:27:11
Original
1778 people have browsed it

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>
Copy after login

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:

Sample code detailing the XML reader

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:

Sample code detailing the XML reader

Chrome Browser

Open the above XML code in Chrome browser. The code is displayed as follows:

Sample code detailing the XML reader

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>
Copy after login

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:

Sample code detailing the XML reader

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template