Hi!
I am using the following php script avaible at php.net:
http://www.php.net/manual/en/ref.xml.php
<?php
$file = "data.xml";
function startElement($parser, $name, $attrs)
{
}
function endElement($parser, $name)
{
}
function characterData($parser, $data)
{
echo $data;
}
$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>
The porblem is that if the characterdata $data contains the & character, the value of $data will not be good.
ex:
<link>http://www.alma.io/as.php?id=12&b=15</link>
In this case the value of $data will be:
http://www.alma.io/as.php?id=12
and NOT
http://www.alma.io/as.php?id=12&b=15
How to solve this problem?
Example of this kind of xml:
http://www.romanialibera.ro/editie/rss.php
And the result of my parser:
http://stiri.traficdublu.ro/xml/rolibera.php
The result is wrong!
Thnaks for your answer!