How to use registerXPathNamespace in PHP

In this article I will explain how registerXPathNamespace function used in PHP.
  • 3193

registerXPathNamespace() Function

This function is helpful if a namespace prefix is changed in an xml file and create a prefix for specified namespace, so that the affected XML nodes can be accessed without modify the application code too much.


class SimpleXMLElement
string registerXPathNamespace(prefix,ns)


XML File

<?xml version="1.0" encoding="ISO-8859-1"?>
<note xmlns:b="">
<writer>wei sang lee</writer>
<b:body>Hello, Dinesh sir Ji.</b:body>

PHP Code

$xml = simplexml_load_file("parse.xml");

$result = $xml->xpath("msg:body");

foreach ($result as $message)
echo $message;



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


More Articles

© 2020 DotNetHeaven. All rights reserved.