Forum Moderators: coopster
i've been following this tutorial and can get it working
<snip>
but what i want to do is take the data from a dynamic aspx xml file
$xml_file = "http://www.example.com/xml/Search.aspx?make=Ford&model=Accord";
i have downloaded the source of this aspx file and saved it as an xml and I can get it to work.
the error I get when trying to parse the dynamic xml is
"Could not read file"
this tells me so far that it has successfully read this file using 'fopen' but it cannot read it using 'fread'
can anyone shine some light on me on how to successfully parse an aspx xml feed with php?
is it something to do with the values in the url?
[edited by: eelixduppy at 6:16 pm (utc) on June 13, 2007]
[edit reason] removed link - see charter [/edit]
-What happens that caused your script to output "Could not read file"? If you don't know, then post just that relevant code.
-Are you getting any PHP errors in your error log?
-Do you have PHP 5 so that you can use simpleXML [php.net]?
.
.
.
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($xml_file, "r") or die("Could not open file");
$data = fread($fp, filesize($xml_file)) or die("Could not read file"); *** Script stops on this line
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
---------
i think the problem lies with filesize($xml_file)
as when i try and echo that directly after declaring the $xml_file, it doesnt output anything...
i have added in this function to the equation:
function extrair_url_curl ($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
so instead of the lines
$fp = fopen($xml_file, "r") or die("Could not open file");
$data = fread($fp, filesize($xml_file)) or die("Could not read file");
i have replaced it simply with:
$data = extrair_url_curl($xml_file);
---
woohoo :)