I am new to XML Parsing so kindly point out any mistakes in my question.
- I have an XML file which I cannot change.
- I have written a php script that obtains the user input through get parameter and then searches the suitaible entry in the xml file. Once it finds the entry based on the get parameter it outputs suitaible XML for that entry.
- The script works fine for most cases which is confirmed by the browser showing specific XML data corresponding to the ID when the script is called in the browser with a get parameter.
Problem: In some cases the XML file contains & . When these entries are called for an XML error is generated by the browser near the ampersand sign. I want to know what exactly is causing the problem and preventing the formation of well formed XML.
Here is my php code...
for($j=0;$j<$length;$j++)
{
$name=$parent->childNodes->item($j)->nodeName;
for($k=0;$k<$num;$k++)
{
if($name==$elements_reqd[$k])
{
$value=$parent->childNodes->item($j)->textContent;
$info=array_push_assoc($info,$elements_reqd[$k],$value);
}
}
}
echo "<LISTING>";
foreach($info as $key => $value)
{
echo "<$key>$value</$key>";
}
echo "</LISTING>";
function array_push_assoc(&$array, $key, $value){
$array[$key] = $value;
return $array;
}