Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building a Web Application with PHP and MariaDB: A Reference Guide

You're reading from   Building a Web Application with PHP and MariaDB: A Reference Guide Build fast, secure, and interactive web applications using this comprehensive guide

Arrow left icon
Product type Paperback
Published in Jun 2014
Publisher
ISBN-13 9781783981625
Length 200 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sai S Sriparasa Sai S Sriparasa
Author Profile Icon Sai S Sriparasa
Sai S Sriparasa
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. CRUD Operations, Sorting, Filtering, and Joins 2. Advanced Programming with MariaDB FREE CHAPTER 3. Advanced Programming with PHP 4. Setting Up Student Portal 5. Working with Files and Directories 6. Authentication and Access Control 7. Caching 8. REST API 9. Security 10. Performance Optimization Index

Generating XML feeds


In the last section, we built our API to fetch the data and print the raw data onto the page. In this section, we will build methods that will take the data and convert them into XML feeds. A remote application can then use these XML feeds to ingest the data. Before we build the XML generation functionality, let's create a class variable that can be used to hold this XML data using the following code in the controllers/api.php file:

public $xml;

Now that we have added the class variable, let's add the following XML generation functionality to our API, present in the controllers/api.php file:

private function _generateXML($root, $data){
  $this->xml = new SimpleXMLElement("<$root/>");

  foreach($data as $key=>$value){
    $this->_generateXMLChild(substr($root, 0, -1), $value);
  }
  header("HTTP/1.1 200 OK");
  header("Content-Type: application/xml; charset=utf-8");
  echo $this->xml->asXML();
}

private function _generateXMLChild($type ,$item){

 ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime