background preloader

Databases

Facebook Twitter

Tutorial: Handling XML data. Introduction This tutorial was originally posted on the old site on 20th December, 2007. XML, Extensible Markup Language, is a general-purpose markup language which can be used for storing arbitrary data in a structured way. It is often used for sharing data between applications and a common usage of XML is for instance RSS feeds. With the emerge of PHP 5, support for handling XML data has greatly improved and in this tutorial we will take a look at the features in PHP 5 which we can use to parse, alter and create XML documents.

Basic knowledge of XML is a prerequisite for this tutorial. Right, let's go to the next page and get started... Parsing XML PHP 5 has a class called SimpleXML which is... simple to use. Throughout this tutorial we will use the file books.xml which I created using data from the top three books on Amazon.com's Editor's Picks: Best Books of 2007. <? We can load our data into SimpleXML in two ways. The second argument is used to set certain options. <? XPath <? <? <? <? <? <? <? Making XML/XSLT driven site using PHP - AnyExample.com. A Really, Really, Really Good Introduction to XML [XML, XSLT & Web Services] In this chapter, we’ll cover the basics of XML – essentially, most of the information you’ll need to know to get a handle on this exciting technology. After we’re done exploring some terminology and examples, we’ll jump right in and start working with XML documents.

Then, we’ll spend some time starting the project we’ll develop through the course of this book: building an XML-powered content management system. This excerpt is taken from No Nonsense XML Web Development with PHP, SitePoint’s new release, by Thomas Myer, which was designed to help you start using XML to build intelligent ‘Future-Proof’ PHP applications today. The title contains over 350 pages of XML and PHP goodies. To find out more about “No Nonsense XML Web Development with PHP”, visit the book’s information page, or review the contents of the entire publication.

Chapter 1. Who here has heard of XML? What is XML? So, what is XML? The essence of XML is in its name: Extensible Markup Language. Extensible XML is extensible. <! XML Parsing using PHP {Easy} Introduction If you are looking at this tutorial then you probably have a good idea in your head about what XML is and what you can do with it. However, for those of you that stumbled across this tutorial on accident and are interested in learning more, I will briefly explain what XML is and what it is used for.

XML stands for eXtensible Markup Language and is used primarily for data storage and organization. It is useful for many things but the main thing I like about it is that there are no predefined tags; the author of the code completely creates the tags as he goes along. A sample xml code could look like this: Formatting XML Ok, so you're probably asking, "Now what? " Now, before I continue I want to let everyone know that the following methods are simply the ways in which I prefer to go about getting the job done.

Creating our XML As with any project, organization is the key. <num>1</num> <num>2</num> <num>3</num> <num>4</num> <num>5</num> <num>6</num> <num>7</num> <num>8</num> <? If(! 1. Output mySQL data as XML with PHP. Output mySQL data as XML with PHP by Jubba Introduction This tutorial will show you how to take data that is stored in your mySQL database and easily turn it into XML. From there you can use the XML however you wish. This is useful for blogs, shoutboxes, guestbooks, or even larger things such as back-end CMS (content management systems) for your site or sites. While writing this tutorial I am making the assumption that if you are looking at this tutorial then you already have a decent grasp of some of the basics of PHP and also that you know basic XML syntax rules.

Most people just take their database and pull the data directly into Flash with the use of a server-side script. Using the XML method helps in a number of ways. MySQL set-up One of the good things about this tutorial is that you will not have to change the structure of your database if you already have begun to fill it up. <? $xml_output .= "</entries>"; echo $xml_output; Easy, right? Well lets get started on the code. XML Parsing using PHP {Intermediate} XML Parsing using PHP {Intermediate} by Jubba Introduction This tutorial is a continuation of the previous XML tutorial I have written. Because I have already written some background information (very little) I will not add that into this tutorial in order to save space and time. The other tutorial can be found at this link.

Formatting XML Ok, since I already went over the basics for formatting XML data and the basics of PHP/XML parsing I'm just going to jump right into the XML and PHP without much of an explanation. For this project I decided to create a mock-news headline parser. Basically, we have our XML file that has news headlines and a brief description of the story. Many of the news-tickers that you see on websites use a process similar to this (often called RSS). Creating our XML Just as with the last tutorial this XML file is quite simple. <headline> Godzilla Attacks LA! <headline> Bigfoot Spotted at M.I.T. <headline> London Angel Saves England </headline> <? If(! Fclose($fp); ? A b. XML and Databases. Copyright 1999-2005 by Ronald Bourret Last updated September, 2005 This article also available in: Table of Contents 1.0 Introduction This paper gives a high-level overview of how to use XML with databases.

It describes how the differences between data-centric and document-centric documents affect their usage with databases, how XML is commonly used with relational databases, and what native XML databases are and when to use them. NOTE: Although the information discussed in this paper is (mostly) up-to-date, the idea that the world of XML and databases can be seen through the data-centric/document-centric divide is somewhat dated. 2.0 Is XML a Database? Before we start talking about XML and databases, we need to answer a question that occurs to many people: "Is XML a database?

" An XML document is a database only in the strictest sense of the term. 3.0 Why Use a Database? For example, suppose you have an e-commerce application that uses XML as a data transport. 4.0 Data versus Documents.