<?php
$dom
=
new
DOMDocument();
$dom
->loadXML("<?xml version=\"1.0\"?>
<root>
<div xmlns:x=\"my_namespace\">
<x:h1 x:style=\"color:red;\">
Hello, this is my red heading.
</x:h1>
<x:h1 x:style=\"color:green;\">
Hello, this is my green heading.
</x:h1>
<x:h1 x:style=\"color:blue;\">
Hello, this is my blue heading.
</x:h1>
</div>
<div xmlns:y=\"another_namespace\">
<y:h1> Hello, this is my
new
red heading. </y:h1>
<y:h1> Hello, this is my
new
green heading. </y:h1>
<y:h1> Hello, this is my
new
blue heading. </y:h1>
</div>
</root>");
$nodeList
=
$dom
->getElementsByTagName(
'h1'
);
$i
= 0;
foreach
(
$nodeList
as
$node
) {
if
(
$node
->hasAttributeNS(
'my_namespace'
,
'style'
)) {
$i
++;
}
}
echo
"Yes, there are total of
$i
style
attributes inside my_namespace";
?>