1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00

Remove code examples from dom extension

PHP documentation is a better place to present code examples. Tests
for ext/dom already include all used PHP code.
This commit is contained in:
Peter Kokot
2017-10-08 03:09:37 +02:00
committed by Nikita Popov
parent 4fcecfb291
commit 60909f391d
14 changed files with 0 additions and 301 deletions
-43
View File
@@ -1,43 +0,0 @@
<?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> ";
function print_node($node)
{
print "Node Name: " . $node->nodeName;
print "\nNode Type: " . $node->nodeType;
$child_count = $node->childNodes->length;
print "\nNum Children: " . $child_count;
if($child_count <= 1){
print "\nNode Content: " . $node->nodeValue;
}
print "\n\n";
}
function print_node_list($nodelist)
{
foreach($nodelist as $node)
{
print_node($node);
}
}
?>
-94
View File
@@ -1,94 +0,0 @@
<?php
require_once("dom1.inc");
echo "Test 1: accessing single nodes from php\n";
$dom = new domDocument;
$dom->loadxml($xmlstr);
if(!$dom) {
echo "Error while parsing the document\n";
exit;
}
// children() of of document would result in a memleak
//$children = $dom->children();
//print_node_list($children);
echo "--------- root\n";
$rootnode = $dom->documentElement;
print_node($rootnode);
echo "--------- children of root\n";
$children = $rootnode->childNodes;
print_node_list($children);
// The last node should be identical with the last entry in the children array
echo "--------- last\n";
$last = $rootnode->lastChild;
print_node($last);
// The parent of this last node is the root again
echo "--------- parent\n";
$parent = $last->parentNode;
print_node($parent);
// The children of this parent are the same children as one above
echo "--------- children of parent\n";
$children = $parent->childNodes;
print_node_list($children);
echo "--------- creating a new attribute\n";
//This is worthless
//$attr = $dom->createAttribute("src", "picture.gif");
//print_r($attr);
//$rootnode->set_attributeNode($attr);
$attr = $rootnode->setAttribute("src", "picture.gif");
$attr = $rootnode->getAttribute("src");
print_r($attr);
print "\n";
echo "--------- Get Attribute Node\n";
$attr = $rootnode->getAttributeNode("src");
print_node($attr);
echo "--------- Remove Attribute Node\n";
$attr = $rootnode->removeAttribute("src");
print "Removed " . $attr . " attributes.\n";
echo "--------- attributes of rootnode\n";
$attrs = $rootnode->attributes;
print_node_list($attrs);
echo "--------- children of an attribute\n";
$children = $attrs->item(0)->childNodes;
print_node_list($children);
echo "--------- Add child to root\n";
$myelement = new domElement("Silly", "Symphony");
$newchild = $rootnode->appendChild($myelement);
print_node($newchild);
print $dom->saveXML();
print "\n";
echo "--------- Find element by tagname\n";
echo " Using dom\n";
$children = $dom->getElementsByTagname("Silly");
print_node_list($children);
echo " Using elem\n";
$children = $rootnode->getElementsByTagName("Silly");
print_node_list($children);
echo "--------- Unlink Node\n";
print_node($children->item(0));
$rootnode->removeChild($children->item(0));
print_node_list($rootnode->childNodes);
print $dom->savexml();
echo "--------- Find element by id\n";
print ("Not implemented\n");
echo "--------- Check various node_name return values\n";
print ("Not needed\n");
?>
-9
View File
@@ -1,9 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>PHP User Group</to>
<from>Shane</from>
<heading>Reminder</heading>
<body>Don't forget the meeting tonight!</body>
<footer>Or I'll clobber you!</footer>
</note>
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
-19
View File
@@ -1,19 +0,0 @@
<?php
$dom = new domDocument;
$dom->load('note.xml');
if (!$dom->validate('note.dtd')) {
print "Document note.dtd is not valid\n";
} else {
print "Document note.dtd is valid\n";
}
$dom = new domDocument;
$dom->load('note-invalid.xml');
if (!$dom->validate('note.dtd')) {
print "Document note-invalid.xml is not valid\n";
} else {
print "Document note-invalid.xml is valid\n";
}
?>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>PHP User Group</to>
<from>Shane</from>
<heading>Reminder</heading>
<body>Don't forget the meeting tonight!</body>
</note>
-11
View File
@@ -1,11 +0,0 @@
<?php
$dom = new domDocument;
$dom->load('relaxNG.xml');
if (!$dom->relaxNGValidate('relaxNG.rng')) {
print "Document is not valid";
} else {
print "Document is valid";
}
?>
-11
View File
@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href="relaxNG2.rng">
<define name="TEI.prose"><ref name="INCLUDE"/></define>
</include>
</grammar>
-1
View File
@@ -1 +0,0 @@
<TEI.2>hello</TEI.2>
-23
View File
@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<ref name="TEI.2"/>
</start>
<define name="IGNORE">
<notAllowed/>
</define>
<define name="INCLUDE">
<empty/>
</define>
<include href="relaxNG3.rng"/>
<define name="TEI.2">
<element name="TEI.2">
<text/>
</element>
</define>
</grammar>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:t="http://www.thaiopensource.com/ns/annotations" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<define name="TEI.prose" combine="interleave">
<ref name="IGNORE"/>
</define>
</grammar>
-11
View File
@@ -1,11 +0,0 @@
<?php
$dom = new domDocument;
$dom->load('shipping.xml');
if (!$dom->schemaValidate('shipping.xsd')) {
print "Document is not valid";
} else {
print "Document is valid";
}
?>
-21
View File
@@ -1,21 +0,0 @@
<?xml version="1.0"?>
<shipOrder>
<shipTo>
<name>Tove Svendson</name>
<street>Ragnhildvei 2</street>
<address>4000 Stavanger</address>
<country>Norway</country>
</shipTo>
<items>
<item>
<title>Empire Burlesque</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shipOrder>
-36
View File
@@ -1,36 +0,0 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="shipOrder" type="order"/>
<xsd:complexType name="order">
<xsd:all>
<xsd:element name="shipTo" type="shipAddress"/>
<xsd:element name="items" type="cdItems"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="shipAddress">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="cdItems">
<xsd:sequence>
<xsd:element name="item" type="cdItem" maxOccurs="unbounded" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="cdItem">
<xsd:all>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:positiveInteger"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>