xref: /PHP-5.3/ext/xml/tests/xml_closures_001.phpt (revision 610c7fbe)
1--TEST--
2XML parser test using closures as callbacks
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--INI--
6magic_quotes_runtime=0
7--FILE--
8<?php
9chdir(dirname(__FILE__));
10
11$start_element = function ($xp, $elem, $attribs)
12{
13	print "<$elem";
14	if (sizeof($attribs)) {
15		while (list($k, $v) = each($attribs)) {
16			print " $k=\"$v\"";
17		}
18	}
19	print ">\n";
20};
21
22$end_element = function ($xp, $elem)
23{
24	print "</$elem>\n";
25};
26
27$xp = xml_parser_create();
28xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
29xml_set_element_handler($xp, $start_element, $end_element);
30$fp = fopen("xmltest.xml", "r");
31while ($data = fread($fp, 4096)) {
32	xml_parse($xp, $data, feof($fp));
33}
34xml_parser_free($xp);
35
36?>
37--EXPECT--
38<root id="elem1">
39<elem1>
40<elem2>
41<elem3>
42<elem4>
43</elem4>
44</elem3>
45</elem2>
46</elem1>
47</root>
48