phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - AJAX: Making XML document use DOM at PHP

Tag: AJAX, DOM, XML   Category:
post: 17 Mar 2008 read: 465


PHP AJAX Step By Step Tutorial - part 1: At this post, we have made application that handle xml data from server. At that post, we create xml document manually. As you know, at PHP, we can create xml document use DOM. Let's do it.

Create a file named "phpdom.php" within www/test/ajax. Enter following code:


<?php
header('Content-type: text/xml');

$dom = new DOMDocument();

$datas = $dom->createElement('datas');
$dom->appendChild($datas);

$id = $dom->createElement('id');
$idText = $dom->createTextNode('1');
$id->appendChild($idText);

$title = $dom->createElement('title');
$titleText = $dom->createTextNode('PHP Undercover');
$title->appendChild($titleText);

$author = $dom->createElement('author');
$authorText = $dom->createTextNode('Wiwit');
$author->appendChild($authorText);

$book = $dom->createElement('book');
$book->appendChild($id);
$book->appendChild($title);
$book->appendChild($author);

$datas->appendChild($book);

$xmlString = $dom->saveXML();
echo $xmlString;

?>

Point your browser to http://localhost/test/ajax/phpdom.php. You will get like:




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting