xref: /PHP-7.4/ext/dom/tests/dom002.phpt (revision aaa1d626)
1--TEST--
2Test 2: getElementsByTagName() / getElementsByTagNameNS()
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7$xml = <<<HERE
8<?xml version="1.0" encoding="ISO-8859-1" ?>
9<foo xmlns="http://www.example.com/ns/foo"
10     xmlns:fubar="http://www.example.com/ns/fubar">
11  <bar><test1 /></bar>
12  <bar><test2 /></bar>
13  <fubar:bar><test3 /></fubar:bar>
14  <fubar:bar><test4 /></fubar:bar>
15</foo>
16HERE;
17
18function dump($elems) {
19	foreach ($elems as $elem) {
20		var_dump($elem->nodeName);
21		dump($elem->childNodes);
22	}
23}
24
25$dom = new DOMDocument();
26$dom->loadXML($xml);
27$doc = $dom->documentElement;
28dump($dom->getElementsByTagName('bar'));
29dump($doc->getElementsByTagName('bar'));
30dump($dom->getElementsByTagNameNS('http://www.example.com/ns/fubar', 'bar'));
31dump($doc->getElementsByTagNameNS('http://www.example.com/ns/fubar', 'bar'));
32?>
33--EXPECT--
34string(3) "bar"
35string(5) "test1"
36string(3) "bar"
37string(5) "test2"
38string(9) "fubar:bar"
39string(5) "test3"
40string(9) "fubar:bar"
41string(5) "test4"
42string(3) "bar"
43string(5) "test1"
44string(3) "bar"
45string(5) "test2"
46string(9) "fubar:bar"
47string(5) "test3"
48string(9) "fubar:bar"
49string(5) "test4"
50string(9) "fubar:bar"
51string(5) "test3"
52string(9) "fubar:bar"
53string(5) "test4"
54string(9) "fubar:bar"
55string(5) "test3"
56string(9) "fubar:bar"
57string(5) "test4"
58