getNamespaces()Namespace are used in XML document to avoid conflict of name used by different XML developers. For example name element can have name of the student or it can have name of the fruits in basket.
We will discuss more on how to get namespace details by using PHP. Here is the example to get namespace from our XML file. We have used one more sample file which used namespace in its elements.
We will use PHP script to get the namespaces from above XML data. Here it is
The output is
By using recursive to TRUE we will get name space of total documents including all child nodes. By making it FALSE it will return only root node namespaces.
Now change this line
We will get only document root namespace
This article is written by plus2net.com team.
PHP & XML getName(): Name of the XML element or tag children(): Children of a XML node count(): Counting number of Children of an XML element simplexml_load_file(): creating object by reading from XML file simplexml_load_string(): creating object by using XML formatted string asXML: Getting string output or writing to file addAttribute(): Adding attribute to element of XML object addChild(): Adding Child element to element of XML object getNamespaces(): Getting NameSpaces from XML object XML from Database(): Generating XML from table records