3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * A few simple static methods for writing XML
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.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
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.
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.
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
50 * Class DB_Table_XML contains a few simple static methods for writing XML
54 * @author David C. Morse <morse@php.net>
55 * @version Release: 1.5.6
56 * @link http://pear.php.net/package/DB_Table
63 * Returns XML closing tag <tag>, increases $indent by 3 spaces
66 * @param string $tag XML element tag name
67 * @param string $indent current indentation, string of spaces
68 * @return string XML opening tag
71 function openTag($tag, &$indent)
73 $old_indent = $indent;
74 $indent = $indent . ' ';
75 return $old_indent . "<$tag>";
80 * Returns XML closing tag </tag>, decreases $indent by 3 spaces
83 * @param string $tag XML element tag name
84 * @param string $indent current indentation, string of spaces
85 * @return string XML closing tag
88 function closeTag($tag, &$indent)
90 $indent = substr($indent, 0, -3);
91 return $indent . "</$tag>";
96 * Returns string single line XML element <tag>text</tag>
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
105 function lineElement($tag, $text, $indent)
107 return $indent . "<$tag>$text</$tag>";