<?php
/*-
* Copyright (c) 2009 Spîria Software - www.spiria.com.uy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* This class show a smple example of how to use the XML class
* and save the xml structure in a file
*
* @author Mauricio Souto - Spîria Software - www.spiria.com.uy
*/
include_once("XML.php");
//always start creating a XML object
$xml = new XML();
//add a root node
$r = $xml->createRoot("categories");
//add the childs of the root file
$food = $r->addChild("category");
$food->addAttribute("name", "food", false);
$drink = $r->addChild("category");
$drink->addAttribute("name", "drink", false);
$dessert = $r->addChild("category");
$dessert->addAttribute("name", "dessert", false);
$art = $food->addChild("article");
$art->addAttribute("name", "chicken", false);
$art->addAttribute("price", "12", false);
$art = $food->addChild("article");
$art->addAttribute("name", "hot dog", false);
$art->addAttribute("price", "5", false);
$art = $food->addChild("article");
$art->addAttribute("name", "hamburger", false);
$art->addAttribute("price", "8", false);
$art = $drink->addChild("article");
$art->addAttribute("name", "coke", false);
$art->addAttribute("price", "3", false);
$art = $drink->addChild("article");
$art->addAttribute("name", "beer", false);
$art->addAttribute("price", "5", false);
$art = $drink->addChild("article");
$art->addAttribute("name", "water", false);
$art->addAttribute("price", "2", false);
$art = $dessert->addChild("article");
$art->addAttribute("name", "chocolate cake", false);
$art->addAttribute("price", "4.5", false);
$art = $dessert->addChild("article");
$art->addAttribute("name", "ice cream", false);
$art->addAttribute("price", "2", false);
//in this other case the atttributes of the node displays in the header of the node, like this <node nameAttribute=value/>
$xml->toFile("xml_files/", "catalog1.xml", false);
//in this case the atttributes of the node displays like the childs, like this <nameAttribute>value</nameAttribute>
$xml->toFile("xml_files/", "catalog2.xml", true);
?>
|