<?php
$dom
=
new
DOMDocument();
$dom
->loadXML("<?xml version=\"1.0\"?>
<root>
<html xmlns:x=\"my_namespace\">
<x:h1 x:id=\"my_id\"> Geeksforgeeks </x:h1>
<x:h2> Second heading </x:h2>
</html>
<html xmlns:y=\"another_namespace\">
<y:h1 id=\"my_new_id\"> Random text </y:h1>
<y:h2> Another heading </y:h2>
</html>
</root>");
$nodes
=
$dom
->getElementsByTagName(
'h1'
);
echo
"Before the removal of attributes: <br>"
;
foreach
(
$nodes
as
$node
) {
$attribute
=
$node
->attributes->item(0);
$attribute_name
=
$attribute
->name;
$attribute_value
=
$attribute
->value;
echo
$attribute_name
.
' => '
;
echo
$attribute_value
.
'<br>'
;
$node
->removeAttributeNS(
'my_namespace'
,
'id'
);
}
echo
"<br>After the removal of attributes: <br>"
;
foreach
(
$nodes
as
$node
) {
$attribute
=
$node
->attributes->item(0);
$attribute_name
=
$attribute
->name;
$attribute_value
=
$attribute
->value;
echo
$attribute_name
.
' => '
;
echo
$attribute_value
.
'<br>'
;
}
?>