Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * This example shows how to use the XML_UNSERIALIZER_OPTION_FORCE_ENUM
4
 * option
5
 *
6
 * @author  Stephan Schmidt <schst@php.net>
7
 */
8
error_reporting(E_ALL);
9
 
10
require_once 'XML/Unserializer.php';
11
 
12
$xml1 = '<root>
13
   <item>
14
     <name>schst</name>
15
   </item>
16
   <item>
17
     <name>luckec</name>
18
   </item>
19
 </root>';
20
 
21
$xml2 = '<root>
22
   <item>
23
     <name>schst</name>
24
   </item>
25
 </root>';
26
 
27
$options = array(
28
                  XML_UNSERIALIZER_OPTION_FORCE_ENUM => array('item')
29
                );
30
 
31
 
32
//  be careful to always use the ampersand in front of the new operator
33
$unserializer = &new XML_Unserializer($options);
34
 
35
// userialize the document
36
$status = $unserializer->unserialize($xml1);
37
 
38
if (PEAR::isError($status)) {
39
    echo 'Error: ' . $status->getMessage();
40
} else {
41
    $data = $unserializer->getUnserializedData();
42
    echo '<pre>';
43
    print_r($data);
44
    echo '</pre>';
45
}
46
 
47
// userialize the document
48
$status = $unserializer->unserialize($xml2);
49
 
50
if (PEAR::isError($status)) {
51
    echo 'Error: ' . $status->getMessage();
52
} else {
53
    $data = $unserializer->getUnserializedData();
54
    echo '<pre>';
55
    print_r($data);
56
    echo '</pre>';
57
}
58
?>