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