XML Error: Invalid character



I have the below php code that is parsing xml from url



$parser=xml_parser_create();

function char($parser,$data)
{
echo $data;
}

xml_set_character_data_handler($parser,"char");
$fp=fopen("http://example.com","r");

while ($data=fread($fp,4096))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}


The xml returned by above fopen call is like this.The Xml don't have any encoding set at top. The above code is outputing XML Error: Invalid character at line 1008 on browser.



<entries> //root element
<entry>
<TITLE><![CDATA[xxxx yyyyyyyyyy]]></TITLE>
</entry>
<entry>
<TITLE><![CDATA[xxxx Gold… yyyyyyyyyy]]></TITLE>//this is line no 1008 that returns invalid character error and script stops
</entry>
</entries>


I think it might be due to ellipses because When I save the xml returned in local file in notepad++ and then feed that xml file the above parser runs good.


I want to run this xml directly from url instead of saving it into directory because that will be a overhead I don't need.Thanks


No comments:

Post a Comment