You said your parsing this file....
xxx://l4eblog.blogspot.com/atom.xml
that get put into the document write JavaScript file!
So your saying...
But if there is a & in content string, it doesn't make into the document write JavaScript file! <= correct?
Now I tried it, using your script, and I got that error (no write), but if I convert it before giving it to the parser, I don't get the error and I can build the JavaScript file even with &(s) in the content string!
Your error is...
XML_ERR_NAME_REQUIRED, in this case, a litiral entity found, which shouldn't be there, they should be encoded....
Simple fix....
// change this....
Code: Select all
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://l4eblog.blogspot.com/atom.xml","r") or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);// to this...
Code: Select all
// temp file....
$temp = './atom.xml';
// download and convert
$data = file_get_contents ( 'http://l4eblog.blogspot.com/atom.xml' );
$old = array ( '&', '&' );
$new = array ( '&', '&' );
file_put_contents ( $temp, str_replace ( $old, $new, $data ) );
unset ( $old, $new, $data );
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("./atom.xml","rb") or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
unlink ( $temp );
xml_parser_free($xml_parser);Edit...
The parser will convert &(s) back to & in strings auotmaticlly!
pif!