summaryrefslogtreecommitdiff
path: root/ext/dom/tests/domelement.phpt
blob: 43a6e986035898b7e50d1560fb9317bc10d4e885 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--TEST--
Elements: DOMElement functionality
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require_once("dom_test.inc");

$dom = new DOMDocument;
$dom->loadXML($xmlstr);
if(!$dom) {
  echo "Error while parsing the document\n";
  exit;
}

$node = $dom->documentElement;
echo "Tag Name: ".$node->tagName."\n";


$node->setAttribute('num', '1');
echo "Chapter: ".$node->getAttribute('num')."\n";
echo 'Attribute num exists?: '.($node->hasAttribute('num')?'Yes':'No')."\n";
$node->removeAttribute('num');
echo "Chapter: ".$node->getAttribute('num')."\n";
echo 'Attribute num exists?: '.($node->hasAttribute('num')?'Yes':'No')."\n";

echo "Language: ".$node->getAttribute('language')."\n";
$lang = $node->getAttributeNode('language');
$lang->nodeValue = 'en-US';
$node->setAttributeNode($lang);
echo "Language: ".$node->getAttribute('language')."\n";
$node->removeAttributeNode($lang);
echo "Language: ".$node->getAttribute('language')."\n";

echo "\n-- xml:lang --\n";
$node->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en');
echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
echo 'Attribute xml:lang exists?: '.($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')?'Yes':'No')."\n";

$node->removeAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
echo 'Attribute xml:lang exists?: '.($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')?'Yes':'No')."\n";

$lang = $dom->createAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang');
$lang->nodeValue = 'en-GB';
$node->setAttributeNodeNS($lang);
unset($lang);
echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
$lang = $node->getAttributeNodeNS('http://www.w3.org/XML/1998/namespace', 'lang');
echo "Language: ".$lang->value."\n";

echo "\n-- Elements --\n";
$rows = $node->getElementsByTagName('row');
echo "Row Count: ".$rows->length."\n";

$element_ns = new DOMElement('newns:myelement', 'default content', 'urn::dummyns');
$node->appendChild($element_ns);
$element_ns = new DOMElement('newns2:myelement', 'second default content', 'urn::dummyns');
$node->appendChild($element_ns);

$myelements = $node->getElementsByTagNameNS('urn::dummyns', 'myelement');
$mylen = $myelements->length;
echo "myelements Count: ".$mylen."\n";

echo "\n-- IDs --\n";
$node->setAttribute('idatt', 'n1');
$node->setIdAttribute('idatt', TRUE);

for ($x = 0; $x < $mylen; $x++) {
	$current = $myelements->item($x);
	$current->setAttributeNS('urn::dummyns', 'newns:idatt', 'n'.($x+2))."\n";
	$current->setIdAttributeNS('urn::dummyns', 'idatt', TRUE);
}

echo 'Element Name: '.(($elem = $dom->getElementByID('n1'))?$elem->localName:'Not Found')."\n";
$idatt = $node->getAttributeNode('idatt');
$node->setIdAttributeNode($idatt, FALSE);
echo 'Element Name: '.(($elem = $dom->getElementByID('n1'))?$elem->localName:'Not Found')."\n";

echo 'Element Name: '.(($elem = $dom->getElementByID('n3'))?$elem->nodeName:'Not Found')."\n";
for ($x = 0; $x < $mylen; $x++) {
	$node = $myelements->item($x);
	$node->setIdAttributeNS('urn::dummyns', 'idatt', FALSE);
}
echo 'Element Name: '.(($elem = $dom->getElementByID('n3'))?$elem->nodeName:'Not Found')."\n";
?>
--EXPECT--
Tag Name: chapter
Chapter: 1
Attribute num exists?: Yes
Chapter: 
Attribute num exists?: No
Language: en
Language: en-US
Language: 

-- xml:lang --
Language: en
Attribute xml:lang exists?: Yes
Language: 
Attribute xml:lang exists?: No
Language: en-GB
Language: en-GB

-- Elements --
Row Count: 3
myelements Count: 2

-- IDs --
Element Name: chapter
Element Name: Not Found
Element Name: newns2:myelement
Element Name: Not Found