PHP
  Home arrow PHP arrow Page 4 - 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  
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? 
Google.com  
PHP

Building XML Trees With PHP
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    Building XML Trees With PHP - A La Carte
    ( Page 4 of 11 )

    Here's another example, this one building a slightly more complicated document tree,

    <?php // include class include("XML/Tree.php"); // instantiate object $tree = new XML_Tree(); // add the root element $root =& $tree->addRoot("recipe"); // add children $name =& $root->addChild("name", "Chicken Tikka"); $author =& $root->addChild("author", "Anonymous"); $ingredients =& $root->addChild("ingredients"); $servings =& $root->addChild("servings", 3); $process =& $root->addChild("process"); // create array of ingredients $ingredientsArray = array( "Boneless chicken breasts, 2", "Chopped onions, 2", "Garlic, 1 tsp", "Ginger, 1 tsp", "Red chili powder, 1 tsp", "Lime juice, 2 tbsp", "Butter, 2 tbsp" ); // create array of steps to execute recipe $stepsArray = array( "Cut chicken into cubes, wash and apply lime juice and salt", "Add ginger, garlic, chili and lime juice in a separate bowl", "Mix well, and add chicken to marinate for 3-4 hours", "Place chicken pieces on skewers and barbeque", "Remove, apply butter, and barbeque again until meat is tender", "Garnish with lemon and chopped onions" ); // add ingredient list to tree foreach ($ingredientsArray as $i) { $item = $ingredients->addChild("item", $i); } // add execution steps to tree foreach ($stepsArray as $s) { $step = $process->addChild("step", $s); } // print tree $tree->dump(); ?>
    and here's the output:

    <?xml version="1.0"?> <recipe> <name>Chicken Tikka</name> <author>Anonymous</author> <ingredients> <item>Boneless chicken breasts, 2</item> <item>Chopped onions, 2</item> <item>Garlic, 1 tsp</item> <item>Ginger, 1 tsp</item> <item>Red chili powder, 1 tsp</item> <item>Lime juice, 2 tbsp</item> <item>Butter, 2 tbsp</item> </ingredients> <servings>3</servings> <process> <step>Cut chicken into cubes, wash and apply lime juice and salt</step> <step>Add ginger, garlic, chili and lime juice in a separate bowl</step> <step>Mix well, and add chicken to marinate for 3-4 hours</step> <step>Place chicken pieces on skewers and barbeque</step> <step>Remove, apply butter, and barbeque again until meat is tender</step> <step>Garnish with lemon and chopped onions</step> </process> </recipe>


     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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 ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek