Xml 简明教程
XML - Viewers
这一章节对各种 methods to view an XML document 进行了描述。可以使用一个简单的文本编辑器或任何浏览器来查看 XML 文档。大多数主流浏览器都支持 XML。XML 文件可以通过双击 XML 文档(如果它是一个本地文件)或者在地址栏中键入 URL 路径(如果该文件位于服务器上),以与我们以相同的方式在浏览器中打开其他文件的方式在浏览器中打开。XML 文件以 ".xml" 扩展名保存。
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.
让我们探讨各种查看 XML 文件的方法。使用以下示例 (sample.xml) 来查看此章的所有章节。
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
可以按如下所示,使用任何简单的文本编辑器(例如记事本、TextPad 或 TextEdit)来创建或查看 XML 文档 −
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
通过双击该文件在 Chrome 中打开以上 XML 代码。XML 代码会以带颜色的编码形式显示,这使得代码更具可读性。它在 XML 元素的左侧显示加号 () 或减号 (-)。当我们单击减号 (-) 时,代码会被隐藏。当我们单击加号 () 时,代码行会得到展开。Firefox 中的输出如下所示 −
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 −

Chrome Browser
在 Chrome 浏览器中打开以上 XML 代码。代码将按如下所示显示 −
Open the above XML code in Chrome browser. The code gets displayed as shown below −

Errors in XML Document
如果 XML 代码缺少一些标签,则会在浏览器中显示一条消息。让我们尝试在 Chrome 中打开以下 XML 文件 −
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>
在以上代码中,起始标签和结束标签不匹配(请参阅 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 −
