Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
 
5
/**
6
 * Examples (file #2)
7
 *
8
 * several examples for the methods of XML_Util
9
 *
10
 * PHP versions 4 and 5
11
 *
12
 * LICENSE:
13
 *
14
 * Copyright (c) 2003-2008 Stephan Schmidt <schst@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 name of the author 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   XML
42
 * @package    XML_Util
43
 * @subpackage Examples
44
 * @author     Stephan Schmidt <schst@php.net>
45
 * @copyright  2003-2008 Stephan Schmidt <schst@php.net>
46
 * @license    http://opensource.org/licenses/bsd-license New BSD License
47
 * @version    CVS: $Id: example2.php,v 1.11 2008/05/05 19:03:13 ashnazg Exp $
48
 * @link       http://pear.php.net/package/XML_Util
49
 */
50
 
51
    /**
52
     * set error level
53
     */
54
    error_reporting(E_ALL);
55
 
56
    require_once 'XML/Util.php';
57
 
58
    /**
59
     * creating a start element
60
     */
61
    print 'creating a start element:<br>';
62
    print htmlentities(XML_Util::createStartElement('myNs:myTag',
63
        array('foo' => 'bar'), 'http://www.w3c.org/myNs#'));
64
    print "\n<br><br>\n";
65
 
66
 
67
    /**
68
     * creating a start element
69
     */
70
    print 'creating a start element:<br>';
71
    print htmlentities(XML_Util::createStartElement('myTag',
72
        array(), 'http://www.w3c.org/myNs#'));
73
    print "\n<br><br>\n";
74
 
75
    /**
76
     * creating a start element
77
     */
78
    print 'creating a start element:<br>';
79
    print '<pre>';
80
    print htmlentities(XML_Util::createStartElement('myTag',
81
        array('foo' => 'bar', 'argh' => 'tomato'),
82
        'http://www.w3c.org/myNs#', true));
83
    print '</pre>';
84
    print "\n<br><br>\n";
85
 
86
 
87
    /**
88
     * creating an end element
89
     */
90
    print 'creating an end element:<br>';
91
    print htmlentities(XML_Util::createEndElement('myNs:myTag'));
92
    print "\n<br><br>\n";
93
 
94
    /**
95
     * creating a CData section
96
     */
97
    print 'creating a CData section:<br>';
98
    print htmlentities(XML_Util::createCDataSection('I am content.'));
99
    print "\n<br><br>\n";
100
 
101
    /**
102
     * creating a comment
103
     */
104
    print 'creating a comment:<br>';
105
    print htmlentities(XML_Util::createComment('I am a comment.'));
106
    print "\n<br><br>\n";
107
 
108
    /**
109
     * creating an XML tag with multiline mode
110
     */
111
    $tag = array(
112
        'qname'        => 'foo:bar',
113
        'namespaceUri' => 'http://foo.com',
114
        'attributes'   => array('key' => 'value', 'argh' => 'fruit&vegetable'),
115
        'content'      => 'I\'m inside the tag & contain dangerous chars'
116
    );
117
 
118
    print 'creating a tag with qualified name and namespaceUri:<br>';
119
    print '<pre>';
120
    print htmlentities(XML_Util::createTagFromArray($tag,
121
        XML_UTIL_REPLACE_ENTITIES, true));
122
    print '</pre>';
123
    print "\n<br><br>\n";
124
 
125
    /**
126
     * create an attribute string without replacing the entities
127
     */
128
    $atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
129
    print 'creating a attribute string, '
130
        . 'entities in values already had been replaced:<br>';
131
    print htmlentities(XML_Util::attributesToString($atts,
132
        true, false, false, false, XML_UTIL_ENTITIES_NONE));
133
    print "\n<br><br>\n";
134
 
135
    /**
136
     * using the array-syntax for attributesToString()
137
     */
138
    $atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
139
    print 'using the array-syntax for attributesToString()<br>';
140
    print htmlentities(XML_Util::attributesToString($atts,
141
        array('entities' => XML_UTIL_ENTITIES_NONE)));
142
    print "\n<br><br>\n";
143
 
144
 
145
?>