mirror of
https://github.com/php/php-src.git
synced 2024-11-26 19:33:55 +08:00
74 lines
1.8 KiB
XML
74 lines
1.8 KiB
XML
<?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);
|
|
|
|
?>
|