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
|
--TEST--
Dom\Node::lookupPrefix()
--EXTENSIONS--
dom
--FILE--
<?php
$dom = Dom\XMLDocument::createFromString(<<<XML
<?xml version="1.0"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:x="test">
<body>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" height="1"/>
<p xmlns:y="test">
<x/>
</p>
</body>
</html>
XML);
$body = $dom->getElementsByTagName("body")[0];
$body->setAttribute("xmlns:a", "urn:a");
echo "--- NULL case because invalid node type ---\n";
var_dump($dom->doctype->lookupPrefix(""));
echo "--- NULL case because xmlns attribute not in xmlns namespace ---\n";
var_dump($body->lookupPrefix("urn:a"));
echo "--- svg case ---\n";
$svg = $dom->getElementsByTagNameNS("*", "svg")[0];
var_dump($svg->lookupPrefix(""));
var_dump($svg->lookupPrefix("http://www.w3.org/2000/svg"));
var_dump($svg->lookupPrefix("1"));
echo "--- search for \"test\" ---\n";
foreach (['x', 'p', 'html'] as $name) {
$x = $dom->getElementsByTagNameNS("*", $name)[0];
var_dump($x->lookupPrefix(""));
var_dump($x->lookupPrefix("test"));
}
?>
--EXPECT--
--- NULL case because invalid node type ---
NULL
--- NULL case because xmlns attribute not in xmlns namespace ---
NULL
--- svg case ---
NULL
string(3) "svg"
NULL
--- search for "test" ---
NULL
string(1) "y"
NULL
string(1) "y"
NULL
string(1) "x"
|