您(Did)是否开始注意到到处都是XML文件?这是很自然的。世界各地正在生成和共享越来越多的数据,而XML可能是最有效的传输方式。
在本文中,您将了解有关XML格式的所有知识。理解XML对于Web 开发(web development)、编程以及任何涉及存储、结构化和传输信息的事情都很重要。继续阅读以了解XML是什么、它的用途以及如何打开XML文件。
什么是 XML?
XML 代表 e X (L)tensible(X) Markup L语言(M)。XML 不是一种编程语言(programming language),而是一种标记语言。您应该了解的另一种非常流行的标记语言是HTML。这些语言使用标签来定义文档中的各种元素,它们是使用我们可以阅读的简单英语单词而不是标准编程语法编写的。
也就是说,XML是一种用于通过 Internet 存储和传输内容的工具。它使用一种几乎任何应用程序都可以理解的简单语言,因此数据很容易被人和机器读取。XML代码如下所示:
任何人都可以阅读和理解XML代码。在上面的示例中,纯文本以黑色书写,标签以红色显示。纯文本是我们在某处存储或发送的信息。标签告诉计算机纯文本是什么类型的数据以及如何处理它。
XML 和 HTML 的区别(The Difference Between XML and HTML)
如前所述,XML是一种类似于HTML的标记语言。它们都用纯文本编写并使用标签。两者的主要区别在于XML是可扩展的。HTML具有预定义的语言,而XML允许您创建无限数量的标记标签来描述内容。
HTML格式化(formats)内容,而 XML存储(stores)内容。
XML 用于什么?
XML 文件是易于创建、共享和存储的纯文本文件。大多数 Web 应用程序使用 XML 来存储数据或与其他应用程序共享数据。
你有没有想过为什么Microsoft Word DOCX文件扩展名的末尾有那个“X”?这是因为XML。自 2007 年以来,Office套件一直依赖XML来构建文档。这同样适用于Excel文件 ( XLSX ) 甚至是现在是PPTX而不是PPT的(PPT)PowerPoint文件。多亏了 XML,计算机可以在需要时快速构建和检索数据。
还有几个其他地方使用了 XML。接下来您将了解这些内容。
互动网站(Interactive Websites)
网站从XML(XML)文件中为其页面获取数据。这是HTML和XML一起使用的地方。如果您正在设计一个动态网站,XML尤其重要。(XML)当内容由于页面的交互性而快速变化时,您需要XML来显示该内容。
站点地图(Sitemaps)
如果您曾经创建过网站,那么您应该了解XML 站点地图(XML sitemaps)。站点地图对于搜索引擎优化非常重要。XML 站点地图用于向Google提供有关您的网页的数据,以便它知道如何对您的网站进行分类和排名。
如何打开 XML 文件?
XML文件是纯文本文件。您可以使用简单的文本编辑器、专用的XML编辑器,甚至是Firefox或Chrome等浏览器打开XML文件。我们将在下面介绍所有 3 种方法。
使用网络浏览器(Using a Web Browser)
如果您只想查看XML文件,您只需要一个 Web 浏览器。任何现代浏览器都可以读取XML文件,无论您使用的是Google Chrome、Firefox还是Edge。
要使用浏览器打开 XML 文件,请右键单击该文件,从菜单中选择打开方式(Open with),然后单击您选择的浏览器。
在我们的示例中,我们使用Internet Explorer打开(Internet Explorer)XML文件,以向您展示即使是浏览器的这种遗物也可以正常工作。这是XML文件的样子。
XML文件中的数据结构良好,并以颜色编码的视图显示。标签显示为紫色,纯文本为黑色,因此信息易于阅读。
这种方法唯一的缺点是你所能做的就是读取数据。你不能编辑它。
使用文本编辑器(Using a Text Editor)
正如多次提到的,XML文件只是文本文件。这意味着您可以使用任何文本编辑器(例如记事本)打开(Notepad)XML文件。当您只需要查看文件、进行少量编辑并与其他人共享时,纯文本编辑器非常棒。
要在记事本中打开(Notepad)XML文件,请右键单击XML文件,再次选择打开方式,然后选择(Open with)记事本(Notepad)。
下面是 XML 文件在记事本(Notepad)中的样子。
XML代码格式正确,但没有颜色编码。这使得阅读变得更加困难,因为您无法立即从纯文本中分辨出标签。
或者,您可以使用更高级的降价编辑器(markdown editors),例如 Notepad++ 和Atom,它们可以突出语法并更好地格式化代码。这是我们的 XML 文件在Atom(Atom)中的样子。
由于行号和针对不同数据类型的附加颜色编码,代码看起来更清晰。
使用在线 XML 编辑器(Using an Online XML Editor)
XML编辑器可以读取文件的内容,对其进行更改,甚至将其转换为不同的格式,例如CSV或JSON。如果您不习惯阅读XML语法,文本通常更容易阅读和理解。
让我们试试XML Viewer,它是一个免费的在线XML编辑器,有几个有用的特性。
导航到XML 查看器(XML Viewer)网页,从XML文件中复制您的(XML)XML代码并将其粘贴到XML 输入(XML Input)窗口中。
或者,您可以单击“浏览(Browse)”按钮上传您的XML文件,或者如果您想从网页链接XML内容,则可以单击“(XML)加载 URL ”按钮。(Load URL )
接下来,您可以选择Tree View以更易读的方式查看文件的内容。
如果您的 XML 代码格式不整齐,您可以选择Tree View下的(Tree View)Beautify选项。
您最喜欢打开和编辑 XML 文件的方式是什么?在下面的评论中让我们知道!
How to Open an XML File and What They’re Used For
Did you start noticing XML files everywhere? That’s only natural. More data is being generated аnd shared everywherе in the world and XML is probably the most efficient methоd of transportation.
In this article, you’ll learn everything you need to know about the XML format. Understanding XML is important for web development, programming, and anything that involves storing, structuring, and transmitting information. Read on to understand what XML is, what’s it used for, and how to open an XML file.
What Is XML?
XML stands for eXtensible Markup Language. XML isn’t a programming language, but a markup language. The other extremely popular markup language you should know about is HTML. These languages use tags to define various elements in a document and they’re written using plain English words that we can read instead of standard programming syntax.
That said, XML is a tool used to store and transmit content through the internet. It uses a simple language that almost any application can understand, so the data is easily read by humans and machines. Here’s what XML code looks like:
Anyone can read and understand XML code. In the example above, the plain text is written in black and the tags appear in red. The plain text is the information we’re storing or sending somewhere. The tags tell the computer what type of data the plain text is and what to do with it.
The Difference Between XML and HTML
As mentioned, XML is a markup language like HTML. Both of them are written in plain text and use tags. The main difference between the two is the fact that XML is extensible. HTML has a predefined language, while XML allows you to create an unlimited number of markup tags to describe the content.
HTML formats content and XML stores content.
What Is XML Used for?
XML files are plain text files that are easy to create, share, and store. Most web applications use XML to store data or share it with other apps.
Did you ever wonder why the Microsoft Word DOCX file extension has that “X” at the end? It’s because of XML. Since 2007, the Office suite has relied on XML for the structure of documents. The same applies to Excel files (XLSX) and even PowerPoint files that are now PPTX instead of PPT. Thanks to XML, computers can quickly structure and retrieve data when it’s needed.
There are a couple of other places where XML is used. You’ll learn about those next.
Interactive Websites
Websites fetch data for their pages from XML files. This is where HTML and XML are used together. XML is especially important if you’re designing a dynamic website. When content changes quickly due to the interactive nature of the page, you need XML to display that content.
Sitemaps
If you ever created a website at some point, you should know about XML sitemaps. Sitemaps are extremely important for search engine optimization. An XML sitemap is used to provide Google with data about your web pages so that it knows how to categorize and rank your website.
How to Open an XML File?
XML files are plain text files. You can open an XML file with a simple text editor, a dedicated XML editor, or even a browser like Firefox or Chrome. We’re going to cover all 3 methods below.
Using a Web Browser
If you just want to view an XML file, all you need is a web browser. Any modern browser can read XML files, whether you’re using Google Chrome, Firefox, or Edge.
To open an XML file with a browser, right-click on the file, select Open with from the menu, and then click on your browser of choice.
In our example, we’re opening the XML file with Internet Explorer to show you that even this relic of a browser works just fine. Here’s what the XML file looks like.
The data inside the XML file is nicely structured and displayed in a color-coded view. The tags appear in purple and the plain text is black, so the information is easy to read.
The only downside of this method is that all you can do is read the data. You can’t edit it.
Using a Text Editor
As mentioned several times, XML files are just text files. This means you can open XML files using any text editor such as Notepad. A plain text editor is great when you just need to view the file, make small edits, and share it with someone else.
To open the XML file in Notepad, right-click on the XML file, select Open with once again, and choose Notepad.
Here’s what the XML file looks like in Notepad.
The XML code is formatted properly, but there’s no color coding. This makes it harder to read because you can’t immediately tell the tags from the plain text.
Alternatively, you can use more advanced markdown editors like Notepad++ and Atom that highlight syntax and do a better job formatting the code. Here’s what our XML file looks like in Atom.
The code looks cleaner thanks to line numbers and additional color coding for different data types.
Using an Online XML Editor
XML editors can read the content of the file, change it, and even convert it to a different format such as CSV or JSON. The text is often easier to read and understand if you’re not used to reading XML syntax.
Let’s try XML Viewer, a free online XML editor with several useful features.
Navigate to the XML Viewer web page, copy your XML code from the XML file and paste it in the XML Input window.
Alternatively, you can click on the Browse button to upload your XML file or on the Load URL button if you want to link XML content from a web page.
Next, you can select Tree View to view the content of the file in a more readable way.
If your XML code isn’t neatly formatted, you can choose the Beautify option that’s right under Tree View.
What’s your favorite way of opening and editing XML files? Let us know in the comments below!