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

Consuming XML

Let's return to the topic of XML. This time, the XML is both served and consumed by PHP. When programming web services, it is common to produce XML output as well as get XML as input. One common example of such an implementation is the SOAP protocol, which isn't covered in this text. Instead of taking a normal query string, we take a full XML document as input. This is a reversal of what we have done thus far. In addition to generating the XML in PHP and reading it in JavaScript, we will do the exact opposite as well.

Another important topic to take into account is handling multiple query terms simultaneously and joining them together. First we need to go back to the design phase and determine how we to format our requests.

Designing the XML Request

We have two search fields to keep in mind when designing our XML request: the title and the author.

As promised, multiple searches can be executed simultaneously. This isn't particularly useful in our application; however, it could be useful in future web application development.

<request>
       <query>
              <title>PHP</title>
              <author>Andrew</author>
       </query>
 </request>

If multiple query nodes are present then the searches will each be executed sequentially. However, now we also need to redesign our XML response because the old response was suitable only for one set of results:

<?xml version="1.0" ?> <catalog> <query title="PHP" author="Andrew"> <book> <Title>Ajax with PHP 5</Title> <Author>Andrew Curioso</Author> <Year>2007</Year> <Publisher>O'Reilly ...
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