How to use getNamespace in PHP

In this article I will explain how getNamespace function used in PHP.
  • 2732

getNamespace() Function

This function takes the namespaces used in an XML document from a Simple XML Element object.

Syntax

class SimpleXMLElement
{
string getNamespace(recursive)
}


Example

XML File

<?xml version="1.0" encoding="ISO-8859-1"?>
<note xmlns:b="https://dotnetheaven.com/articles/">
<book>iPhone</book>
<writer>wei sang lee</writer>
<name>Reminder</name>
<b:body>Don't forget me this weekend!</b:body>
</note>

PHP Code

<html>
<body>
<?php
if (file_exists("parse.xml"))
{
$xml = simplexml_load_file("parse.xml");
}
print_r($xml->getNamespaces());
?>
</body>
</html>

Output

 getNamespace-PHP.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.