blob: c7012e0e3c1a02e66b1fa3211b190f7ede7aba43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
$xmlstr = "<?xml version='1.0' standalone='yes'?>
<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
[ <!ENTITY sp \"spanish\">
]>
<!-- lsfj -->
<chapter language='en'><title language='en'>Title</title>
<para language='ge'>
&sp;
<!-- comment -->
<informaltable language='&sp;kkk'>
<tgroup cols='3'>
<tbody>
<row><entry>a1</entry><entry morerows='1'>b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
</chapter> ";
echo "Test 1: accessing single nodes from php\n";
$dom = xmldoc($xmlstr);
if(!$dom) {
echo "Error while parsing the document\n";
exit;
}
$children = $dom->childNodes();
print_r($children);
echo "--------- root\n";
$rootnode = $dom->documentElement();
print_r($rootnode);
echo "--------- children of root\n";
$children = $rootnode->childNodes();
print_r($children);
// The last node should be identical with the last entry in the children array
echo "--------- last\n";
$last = $rootnode->lastChild();
print_r($last);
// The parent of this last node is the root again
echo "--------- parent\n";
$parent = $last->parent();
print_r($parent);
// The children of this parent are the same children as one above
echo "--------- children of parent\n";
$children = $parent->childNodes();
print_r($children);
echo "--------- creating a new attribute\n";
$attr = $dom->createAttribute("src", "picture.gif");
print_r($attr);
$rootnode->setAttributeNode($attr); /* Not implemented */
$attr = $rootnode->setAttribute("src", "picture.gif");
$attr = $rootnode->getAttribute("src");
print_r($attr);
echo "--------- attribute of rootnode\n";
$attrs = $rootnode->attributes();
print_r($attrs);
echo "--------- children of an attribute\n";
$children = $attrs[0]->childNodes();
print_r($children);
?>
|