1

我正在学习 PHP 和网络编码。
具体来说,我正在使用的涵盖 PHP 5.3 的 PHP 书(由 Matt Doyle 撰写并由 Wrox 出版)说:

XML ... 允许您创建可以以结构化方式保存数据的文本文档...
XML 并不是真正的语言,而是创建您自己的标记语言的规范...

维基百科谈到 XML:

截至 2009 年,已经开发了数百种基于 XML 的语言,[8] 包括 RSS、Atom、SOAP 和 XHTML。基于 XML 的格式已成为许多办公生产力工具的默认格式,包括 Microsoft Office (Office Open XML)、OpenOffice.org 和 LibreOffice (OpenDocument),以及 Apple 的 iWork。 [9] XML 也被用作 XMPP 等通信协议的基础语言。

听起来 XML 更像是一种协议,一种允许计算机通信和共享信息的标准。

所以 XML 就像我可以用来创建标记语言的语法,但我创建的语言只是格式化数据?

我需要帮助定义 PHP 和 XML 之间的关系。在 PHP 和 HTML 的处理过程中,XML 何时被解析?

4

3 回答 3

4

XML 不是语法(这完全是另一回事)。XML(顾名思义)是一种标记语言,它本质上定义了一组描述某事物的规则。“某物”可以是协议、文档结构或任何类型的数据。XML 被设计为机器可读和人类可读(尽管在我看来,对前者有偏见;))。

XML 文档使用一种称为模式的东西来描述 XML 本身的结构,因此您可以根据模式验证 XML 文档以确保其格式正确。

PHP 和 XML 之间没有关系。XML 是 PHP 可以使用和生成的东西。在处理过程中,PHP 不会使用或生成 XML,除非您明确告诉 PHP 这样做。

XML is sometimes used as sort a of "glue" that allows dissimilar or disparate systems to communicate with each other, but even that is just one of its functions. For example, PHP can consume XML produced by a program written in another language entirely, or XML produced by some website. PHP can also produce XML which can then be consumed by a program written in another language, or by some other source. As you found from the Wikipedia article, SOAP uses XML and this allows clients written in different languages to consume data exposed by a SOAP service.

于 2012-08-28T00:05:25.697 回答
0

XML gives a starting point for a lot of technologies, particularly web technologies.

While PHP can be used for other things, its origins are in the web and it is still most heavily used there. As such, it would be sorely lacking if it couldn't deal with such a core web technology as XML. Likewise, it has support for other key web technologies like URIs, and those heavily used with the web like streams and database connections.

于 2012-08-28T00:09:47.427 回答
0

XML is only a data format specification. It was once very hipped but has somewhat faded in favor of JSON - it is still VERY popular because there are many protocols using it as the data interchange format.

PHP is generic enough (as a programming language) to generate XML as well as any other data format.

Since XML is such an important data format, every respectable programming language is expected to easily consume XML as well, and PHP is no exception.

于 2012-08-28T00:10:43.993 回答