PHP
  Home arrow PHP arrow Page 2 - Building XML Trees With PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Building XML Trees With PHP
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24
    2003-02-20

    Table of Contents:
  • Building XML Trees With PHP
  • A Hero Is Born
  • Anatomy Class
  • A La Carte
  • Slice And Dice
  • Killing Off The Kids
  • Rank And File
  • Spider, Spider On The Wall...
  • Making Friends And Influencing People
  • Doing The Chameleon
  • Linking Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Building XML Trees With PHP - A Hero Is Born


    (Page 2 of 11 )

    The XMLTree class comes courtesy of PEAR, the PHP Extension and Application Repository (http://pear.php.net). In case you didn't know, PEAR is an online repository of free PHP software, including classes and modules for everything from data archiving to XML parsing. When you install PHP, a whole bunch of PEAR modules get installed as well; the XMLTree class is one of them.

    In case your PHP distribution didn't include XMLTree, you can get yourself a copy from the official PEAR Web site, at http://pear.php.net - simply unzip the distribution archive into your PEAR directory and you're ready to roll!

    Let's begin with something simple - dynamically constructing an XML document using XMLTree methods. Here's the code:


    <?php // include class include("XML/Tree.php"); // instantiate object $tree = new XML_Tree(); // add the root element $root =& $tree->addRoot("superhero"); // add child elements $name =& $root->addChild("name", "Peter Parker aka Spiderman"); $age =& $root->addChild("age", 21); // print tree $tree->dump(); ?>


    Don't worry if it didn't make too much sense - all will be explained shortly. For the moment, just feast your eyes on the output:


    <?xml version="1.0"?> <superhero> <name>Peter Parker aka Spiderman</name> <age>21</age> </superhero>


    As you can see, the output of the script is a correctly-formatted, well-formed XML document - all created using PHP code!

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway