Skip to Main Content
Ajax with PHP 5
book

Ajax with PHP 5

by Andrew Curioso
May 2007
Intermediate to advanced content levelIntermediate to advanced
56 pages
1h 34m
English
O'Reilly Media, Inc.
Content preview from Ajax with PHP 5

Serving XML

In the previous section, "The "Hello World" of Ajax and PHP," data was served up as plain text. This is great when no post-processing is necessary. However, most applications require the data to be displayed a specific way. You could answer the request with formatted HTML instead of plain text, but then the web application is limited in how it can use the data. We want to separate data and display functionality. Instead, we use markup and data encoding to transmit the data in a format that both PHP and JavaScript can understand without dictating how it should be displayed. The first such format, and arguably the most common, is XML.

We will tackle the XML problem on two fronts: the server using PHP and the consumer (client) using JavaScript. We take on the server first. But before we do anything, we need to agree on a format for our data.

Designing an XML File

XML is a markup language that can be used to encapsulate any type of data that is transmitted over the network or stored on a disk. By definition, the format is generic (extensible) and does not automatically indicate the type of data that it contains. We have to create the format. In this sense XML is a self-descriptive language.

The document always starts with a directive telling the XML parser that the file is indeed XML. The directive also tells the parser the version and optionally the encoding type of the data. Encoding type is the format in which each character in the file is stored.

XML documents always consist ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro PHP and jQuery

Pro PHP and jQuery

Jason Lengstorf
Expert PHP and MySQL®

Expert PHP and MySQL®

Andrew Curioso, Ronald Bradford, Patrick Galbraith

Publisher Resources

ISBN: 9780596514037Purchase LinkErrata Page