I know this question is asked many times before but still can't find the desired result I have been looking for parsing xml document using php DOMDocument function.
Initially my xml document named 'local.xml' contains the following script
<?xml version="1.0" encoding="utf-8"?>
<config>
<global>
<host><![CDATA[name123]]></host>
<username><![CDATA[root45]]></username>
</global>
</config>
I want to change "<host><![CDATA[name123]]></host>" to "<host><![CDATA[name456]]></host>"
I have php code that can change the value inside tag. Here is the php code
<?php
$doc = new DOMDocument();
$doc->load('local.xml');
$config = $doc->getElementsByTagName( "global" );
foreach( $config as $global )
{
$hosts=$global->getElementsByTagName( "host" );
$usernames=$global->getElementsByTagName( "username" );
$a = "<![CDATA[name456]]>";
$hosts1=$hosts->item(0)->nodeValue=$a;
}
$doc->save('local.xml');
?>
When i execute the above code, the output in the xml file is coming as
<?xml version="1.0" encoding="utf-8"?>
<config>
<global>
<host><![CDATA[name456]]></host>
<username><![CDATA[root45]]></username>
</global>
</config>
How can I convert "<" to "<" and ">" to ">" in xml document?
I have tried $a = htmlspecialchars("<![CDATA[name456]]>"); as well as $a = html_entity_decode("<![CDATA[name456]]>"); still it is giving the same output as seen above.