Friday, August 29, 2025
HomeLanguagesPHP | DOMNode isDefaultNamespace() Function

PHP | DOMNode isDefaultNamespace() Function

The DOMNode::isDefaultNamespace() function is an inbuilt function in PHP which is used to check if the specified namespaceURI is the default namespace or not.

Syntax:

bool DOMNode::isDefaultNamespace( string $namespaceURI )

Parameters: This function accepts a single parameter $namespaceURI which holds the namespace URI.

Return Value: This function return TRUE if namespaceURI is the default namespace, FALSE otherwise.

Below examples illustrate the DOMNode::isDefaultNamespace() function in PHP:

Example 1:




<?php
   
// Create a new DOMDocument
$dom = new DOMDocument();
   
// Create a paragraph element with a namespace
$p_element = $dom->createElementNS(
    'my_namespace', 'p', 'neveropen');
   
// Append the child to DOMDocument
$dom->appendChild($p_element);
   
// Check if the namespace is default or not
if($dom->isDefaultNamespace('my_namespace')) {
    echo 'Yes, my_namespace is the default namespace.';
}
?>


Output:

Yes, my_namespace is the default namespace.

Example 2:




<?php
  
// Create a new DOMDocument
$dom = new DOMDocument();
   
// Create a paragraph element with a namespace
$p_element = $dom->createElementNS(
    'my_namespace', 'p', 'neveropen');
   
// Append the child to DOMDocument
$dom->appendChild($p_element);
   
// Check if the namespace is default or not
if(!$dom->isDefaultNamespace('some_other_namespace'))
{
    echo 'No, some_other_namespace is not'
                         . ' default namespace.';
}
?>


Output:

No, some_other_namespace is not the default namespace.

Reference: https://www.php.net/manual/en/domnode.isdefaultnamespace.php

RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11791 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7012 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS