1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * A few simple static methods for writing XML 7 * 8 * PHP versions 4 and 5 9 * 10 * LICENSE: 11 * 12 * Copyright (c) 1997-2007, Paul M. Jones <pmjones@php.net> 13 * David C. Morse <morse@php.net> 14 * Mark Wiesemann <wiesemann@php.net> 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 21 * * Redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer. 23 * * Redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution. 26 * * The names of the authors may not be used to endorse or promote products 27 * derived from this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 30 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 31 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 37 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * @category Database 42 * @package DB_Table 43 * @author David C. Morse <morse@php.net> 44 * @license http://opensource.org/licenses/bsd-license.php New BSD License 45 * @version CVS: $Id: XML.php,v 1.2 2007/12/13 16:52:15 wiesemann Exp $ 46 * @link http://pear.php.net/package/DB_Table 47 */ 48 49/** 50 * Class DB_Table_XML contains a few simple static methods for writing XML 51 * 52 * @category Database 53 * @package DB_Table 54 * @author David C. Morse <morse@php.net> 55 * @version Release: 1.5.6 56 * @link http://pear.php.net/package/DB_Table 57 */ 58 59class DB_Table_XML 60{ 61 62 /** 63 * Returns XML closing tag <tag>, increases $indent by 3 spaces 64 * 65 * @static 66 * @param string $tag XML element tag name 67 * @param string $indent current indentation, string of spaces 68 * @return string XML opening tag 69 * @access public 70 */ 71 function openTag($tag, &$indent) 72 { 73 $old_indent = $indent; 74 $indent = $indent . ' '; 75 return $old_indent . "<$tag>"; 76 } 77 78 79 /** 80 * Returns XML closing tag </tag>, decreases $indent by 3 spaces 81 * 82 * @static 83 * @param string $tag XML element tag name 84 * @param string $indent current indentation, string of spaces 85 * @return string XML closing tag 86 * @access public 87 */ 88 function closeTag($tag, &$indent) 89 { 90 $indent = substr($indent, 0, -3); 91 return $indent . "</$tag>"; 92 } 93 94 95 /** 96 * Returns string single line XML element <tag>text</tag> 97 * 98 * @static 99 * @param string $tag XML element tag name 100 * @param string $text element contents 101 * @param string $indent current indentation, string of spaces 102 * @return string single-line XML element 103 * @access public 104 */ 105 function lineElement($tag, $text, $indent) 106 { 107 return $indent . "<$tag>$text</$tag>"; 108 } 109 110} 111?> 112