PHP
  Home arrow PHP arrow Page 6 - Data Exchange with XML, WDDX and PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Data Exchange with XML, WDDX and PHP
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2001-09-13


    Table of Contents:
  • Data Exchange with XML, WDDX and PHP
  • The Wonderful World Of WDDX
  • Polly Wants A Cracker
  • Humbert Redfinch-Northbottom The Third, I Presume?
  • Old Friends And New
  • Hip To Be Square
  • The Truth Is Out There
  • Money Talks
  • Closing Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Data Exchange with XML, WDDX and PHP - Hip To Be Square
    ( Page 6 of 9 )

    The wddx_packet_start(), wddx_add_vars() and wddx_packet_end() functions are used in tandem, to create a WDDX packet and add variables to it one after another. This comes in handy if you're adding values in a loop, or retrieving them from a database. Consider the following example, which creates a WDDX structure containing the squares of numbers between 1 and 10.

    <? // variable prefix $prefix="square_of_"; // create packet $wp = wddx_packet_start(); // add variables to it for ($x=1; $x<=10; $x++) { // dynamically generate variable name $varname = $prefix . $x; $$varname = pow($x, 2); // add to packet wddx_add_vars($wp, "$prefix$x"); } // end and print echo wddx_packet_end($wp); ?>
    In this case, I'm first starting a new WDDX packet with the wddx_packet_start() function, which returns a WDDX resource handle for further use; this handle is used for all subsequent operations.

    Next, I generate the squares of all numbers between 1 and 10 using a loop, dynamically generate a variable name to hold the value, and add this variable to the packet via the wddx_add_vars() function. This function works exactly like wddx_serialize_vars() - you can specify a list of variables to be added if you like - and requires you to specify the WDDX resource handle generated in the first step.

    Once the packet has been generated, the wddx_packet_end() function is used to add the closing tags to the generated WDDX packet.

    Here's the output:

    <wddxPacket version='1.0'><header/> <data> <struct> <var name='square_of_1'><number>1</number></var> <var name='square_of_2'><number>4</number></var> <var name='square_of_3'><number>9</number></var> <var name='square_of_4'><number>16</number></var> <var name='square_of_5'><number>25</number></var> <var name='square_of_6'><number>36</number></var> <var name='square_of_7'><number>49</number></var> <var name='square_of_8'><number>64</number></var> <var name='square_of_9'><number>81</number></var> <var name='square_of_10'><number>100</number></var> </struct> </data> </wddxPacket>


     
     
    >>> More PHP Articles          >>> More By Vikram Vaswani, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT