2012-08-28 00:03



I'm learning about PHP and web coding.
Specifically, the PHP book I'm using that covers PHP 5.3 (by Matt Doyle and published by Wrox), says:

XML ... lets you create text documents that can hold data in a structured way...
XML isn't really a language but rather a sepcification for creating your own markup languages...

Wikipedia says of XML:

As of 2009, hundreds of XML-based languages have been developed,[8] including RSS, Atom, SOAP, and XHTML. XML-based formats have become the default for many office-productivity tools, including Microsoft Office (Office Open XML), OpenOffice.org and LibreOffice (OpenDocument), and Apple's iWork.[9] XML has also been employed as the base language for communication protocols, such as XMPP.

It sounds like XML is more like a protocol, a standard for allowing compuers to communicate and share information.

So XML is like a grammar I can use to create a markup language, but the language I create only formats data?

I want help defining the relationship between PHP and XML. When during the processesing of PHP and HTML does XML get parsed?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • donglan6777 donglan6777 9年前

    XML is not a grammar (that's another thing entirely). XML (as the name suggests) is a markup language that essentially defines a set of rules that describe something. The "something" could be a protocol, the structure of a document, or any kind of data. XML is designed to be machine readable and human readable (although in my opinion, with bias towards the former ;)).

    XML documents use something called a schema which describes the structure of the XML itself, and so you can validate an XML document against a schema to make sure that it is well-formed.

    There is no relation between PHP and XML. XML is something that PHP can consume and produce. There is nowhere during processing that PHP consumes or produces XML unless you explicitly tell PHP to do so.

    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.

    点赞 评论 复制链接分享
  • donh61500 donh61500 9年前

    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.

    点赞 评论 复制链接分享
  • douzou0073 douzou0073 9年前

    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.

    点赞 评论 复制链接分享