Syntax:DOMElement DOMDocument::createElementNS (string $namespaceURI, string $qualifiedName, string $value)
Parameters:This function takes three parameters as above and described below: - $namespaceURI:This parameter contains the namespace URI.
- $qualName:This parameter contains the full name of the element as a prefix: tagname.
- $value:this parameter contains the value of the element. The default value of this parameter is empty or absent, which means that an empty element was created.
Return value:This function returns a new DOMElement on success or FALSE on failure .The following programs illustrate the DOMDocument::createElementNS() function in PHP:Program 1:
// Create a new one DOMDocument
$dom
=
new
DOMDocument (
’1.0’
,
’ utf-8’
);
// Use the createElementNS() function to create a new one
// node element with associated namespace
$element
=
$dom
-> createElementNS (
’ https://www.engineerforengineer.org/php ’
,
’php: function’
,
’Welcome to GeeksforGeeks’
);
// Add a child element
$dom
-> appendChild (
$element
);
// Create an XML document and submit it
echo
$dom
-> saveXML();
?>
Exit: Welcome to GeeksforGeeks < / php: function >
Program 2:
// Create a new DOMDocument
$dom
=
new
DOMDocument (
’ 1.0’
,
’utf-8’
);
// Use the createElementNS() function to create a new one
// node element with associated namespace
$element1
=
$dom
-> createElementNS (
’ https://www.engineerforengineer.org/php ’
,
’organization: GeeksforGeeks’
,
’A computer science portal’
);
$element2
=
$dom
-> createElementNS (
’ https://www.engineer.org/html ’
,
’php: link’
,
’Welcome to GeeksforGeeks’
);
$element3
=
$dom
-> createElementNS (
’ https://www.engineerforengineer.org/algo ’
,
’algo: link’
,
’Best coding platform’
);
// Add a child element
$dom
-> appendChild (
$element1
);
$dom
-> appendChild (
$element2
);
$dom
-> appendChild (
$element3
);
// Create an XML document and submit it
echo
$dom
-> saveXML();
?>
Exit: < organization: GeeksforGeeks xmlns: organization = "https://www.engineerforengineer.org/php" > A computer science portal < / organization: GeeksforGeeks > Welcome to GeeksforGeeks < / php: link > Best coding platform
Link: https://www.php.net/ manual / en / domdocument.createelementns.php