php-src/tests/testdom

74 lines
1.8 KiB
Plaintext
Raw Normal View History

2000-01-26 14:22:44 +08:00
<?php
$xmlstr = "<?xml version='1.0' standalone='yes'?>
<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
[ <!ENTITY sp \"spanish\">
]>
<!-- lsfj -->
2000-01-26 14:22:44 +08:00
<chapter language='en'><title language='en'>Title</title>
<para language='ge'>
&sp;
<!-- comment -->
<informaltable language='&sp;kkk'>
2000-01-26 14:22:44 +08:00
<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;
}
2000-01-26 14:22:44 +08:00
$children = $dom->childNodes();
print_r($children);
echo "--------- root\n";
$rootnode = $dom->documentElement();
print_r($rootnode);
2000-02-04 05:12:30 +08:00
echo "--------- children of root\n";
$children = $rootnode->childNodes();
print_r($children);
2000-11-10 18:28:30 +08:00
// 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);
2000-11-10 18:28:30 +08:00
2000-01-26 14:22:44 +08:00
?>