Annotation of embedaddon/php/ext/simplexml/tests/017.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SimpleXML: iteration through subnodes
3: --SKIPIF--
4: <?php if (!extension_loaded("simplexml")) print "skip"; ?>
5: --FILE--
6: <?php
7: $xml =<<<EOF
8: <people>
9: <person name="Joe">
10: <child name="Ann" />
11: <child name="Marray" />
12: </person>
13: <person name="Boe">
14: <child name="Joe" />
15: <child name="Ann" />
16: </person>
17: </people>
18: EOF;
19: $xml1 =<<<EOF
20: <people>
21: <person name="Joe">
22: <child name="Ann" />
23: </person>
24: </people>
25: EOF;
26:
27: function print_xml($xml) {
28: foreach($xml->children() as $person) {
29: echo "person: ".$person['name']."\n";
30: foreach($person->children() as $child) {
31: echo " child: ".$child['name']."\n";
32: }
33: }
34: }
35:
36: function print_xml2($xml) {
37: $persons = 2;
38: for ($i=0;$i<$persons;$i++) {
39: echo "person: ".$xml->person[$i]['name']."\n";
40: $children = 2;
41: for ($j=0;$j<$children;$j++) {
42: echo " child: ".$xml->person[$i]->child[$j]['name']."\n";
43: }
44: }
45: }
46:
47: echo "---11---\n";
48: print_xml(simplexml_load_string($xml));
49: echo "---12---\n";
50: print_xml(simplexml_load_string($xml1));
51: echo "---21---\n";
52: print_xml2(simplexml_load_string($xml));
53: echo "---22---\n";
54: print_xml2(simplexml_load_string($xml1));
55: ?>
56: ===DONE===
57: --EXPECTF--
58: ---11---
59: person: Joe
60: child: Ann
61: child: Marray
62: person: Boe
63: child: Joe
64: child: Ann
65: ---12---
66: person: Joe
67: child: Ann
68: ---21---
69: person: Joe
70: child: Ann
71: child: Marray
72: person: Boe
73: child: Joe
74: child: Ann
75: ---22---
76: person: Joe
77: child: Ann
78: child:
79: person:
80:
81: Notice: Trying to get property of non-object in %s017.php on line %d
82: child:
83:
84: Notice: Trying to get property of non-object in %s017.php on line %d
85: child:
86: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>