xml和html有何不同_什么是XML? 与HTML有何不同?

xml和html有何不同

XML is short for Extensible Markup Language, and exists to easily transfer data from one location to another, as well as store it. Less experienced web developers tend to get confused over XML because in plain sight, it isn’t extremely clear what XML is and just what it is used for – when it really is very quite simple. XML is, quite literally, nothing more than a way to transport data and store it. It does not do anything that HTML does, even though the syntax looks strikingly similar.

XML是可扩展标记语言的缩写,并且可以轻松地将数据从一个位置传输到另一位置并进行存储。 经验不足的Web开发人员往往会对XML感到困惑,因为从显而易见的角度来看,XML到底是什么以及它的用途还不是很清楚-当它确实非常简单时。 从字面上看,XML只是传输数据和存储数据的一种方式。 即使语法看起来非常相似,它也不会执行HTML所做的任何事情。

What are the differences between HTML and XML? Aside from the fact they’re completely different things, take note that:

HTML和XML有什么区别? 除了它们是完全不同的事实之外,请注意:

XML does not have any predefined “tags” like HTML does

XML没有像HTML一样的任何预定义“标签”

As XML is used to store and transport data – as a developer – you would naturally need to specify what “tags” hold different types of data, and what these tags are called. For this reason, there are no predefined tags in the XML spec, unlike HTML.

作为开发人员,使用XML来存储和传输数据时,您自然需要指定哪些“标签”保存不同类型的数据,以及这些标签称为什么。 因此,与HTML不同,XML规范中没有预定义标签。

XML does not do anything HTML does

XML不能做HTML

While HTML is used for the display of information, and how that is structured and appears, XML does nothing that HTML does – only transport data. As a matter of fact, XML really does nothing at all.

尽管HTML用于显示信息以及信息的结构和外观,但XML却没有HTML所能做的-仅传输数据。 实际上,XML根本不执行任何操作。

XML is not a replacement to HTML

XML不能替代HTML

In web applications, XML is most commonly used to transport data from one application to another, or one script to another. However, XML is not a replacement to HTML. In fact, XML is also commonly used in desktop applications too.

在Web应用程序中,XML最常用于将数据从一个应用程序传输到另一个应用程序,或将一个脚本传输到另一个脚本。 但是,XML不能替代HTML。 实际上,XML也也经常在桌面应用程序中使用。

So you might be wondering, how is XML used in a real-world scenario?

因此,您可能想知道,在实际场景中如何使用XML?

A good example to work from is a search engine. Say you have a web application that pulls some results from a search engine. This particular search engine allows developers to fetch queries and display them in their web application. When you make a search query via your web application, how would the search engine return the results back? XML is made just for these kinds of scenarios. Here is an illustration of what the XML structure could look like:

搜索引擎就是一个很好的例子。 假设您有一个Web应用程序,可以从搜索引擎中提取一些结果。 这个特定的搜索引擎允许开发人员获取查询并将其显示在Web应用程序中。 通过Web应用程序进行搜索查询时,搜索引擎将如何返回结果? XML仅用于此类情况。 这是XML结构的示意图:

<resultset>
<result>
<title>UK Web Hosting</title>
<description>Leading web hosting provider in the UK</description>
<url>http://www.eukhost.com</url>
</result>

 

<result>
<title>Linux Dedicated Server Hosting</title>
<description>Fully managed servers from eUKhost</description>
<url>http://www.eukhost.com/dedicated-server-hosting.php</url>
</result>
</resultset>

Because XML is only used to transport data, this XML code does nothing in itself. If you opened an XML document in a Web browser, nothing would be displayed except the raw XML source code that you see above. The above XML data becomes useful when you tie it into an application of some kind that makes use of it.

因为XML仅用于传输数据,所以此XML代码本身不执行任何操作。 如果在Web浏览器中打开XML文档,则除了上面看到的原始XML源代码外,将不会显示任何内容。 当您将上述XML数据绑定到某种利用它的应用程序时,它会变得很有用。

So in the case of this imaginary application which fetches results from a search engine – now that the XML data has been returned by the search engine to the application, the developer would have coded some functionality to read the XML data. Because XML code is always structured in the same logical manner, a developer would simply need to write code to read the values of the above tags (that is, tags within <result>) as and when a search query is sent from the application to the search engine. The application would fetch the value of each tag and display it to the end user.

因此,在这个虚构的应用程序从搜索引擎获取结果的情况下-既然搜索引擎已将XML数据返回给应用程序,则开发人员将已经编写了一些功能来读取XML数据。 因为XML代码始终以相同的逻辑方式构造,所以开发人员只需要编写代码来读取上述标记(即<result>中的标记)的值,就像当从应用程序向其中发送搜索查询时一样。搜索引擎。 应用程序将获取每个标签的值并将其显示给最终用户。

What other use cases does XML have?

XML还有哪些其他用例?

Many! There is a Firefox plugin called “HTTPS Everywhere” which always makes sure you are connected over SSL to popular websites like Twitter, Facebook, Google, etc. This plugin also allows you to add your own rulesets in the plugin (in other words, add other websites not included by default to switch to SSL automatically whenever you visit them). Default and custom rulesets in this plugin are simply XML files which the plugin would read – and if a match is found whenever you type in a URL in the address bar– the plugin automatically changes the target address from “http” to “https”.

许多! 有一个名为“ HTTPS Everywhere”的Firefox插件,该插件始终确保您通过SSL连接到流行的网站,例如Twitter,Facebook,Google等。该插件还允许您在插件中添加自己的规则集(换句话说,添加其他默认情况下未包含的网站在您访问它们时会自动切换到SSL)。 该插件中的默认规则集和自定义规则集只是插件将读取的XML文件-如果在地址栏中键入URL时发现匹配,则插件会自动将目标地址从“ http”更改为“ https”。

In our next article, we’ll explain how you can read XML from your web applications using JavaScript (using the jQuery framework) and PHP.

在下一篇文章中,我们将说明如何使用JavaScript(使用jQuery框架)和PHP从Web应用程序读取XML。

翻译自: https://www.eukhost.com/blog/webhosting/what-is-xml-how-is-it-different-to-html/

xml和html有何不同

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值