I'm parsing an XML file and displaying the results, but I'm having problems open the xml url. I keep getting the error message:
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
Here's the code:
$file="http://somexmlfile.com/";
$counter = 0;
$type = 0;
$tag = "";
$itemInfo = array();
$channelInfo = array();
function opening_element($xmlParser, $name, $attribute){
global $tag, $type;
$tag = $name;
if($name == "RESULTLIST"){
$type = 1;
}
else if($name == "RESULT"){
$type = 2;
}
}//end opening element
function c_data($xmlParser, $data){
global $tag, $type, $channelInfo, $itemInfo, $counter;
$data = trim(htmlspecialchars($data));
if($tag == "TITLE" || $tag == "DESCRIPTION"){
if($type == 1){
$channelInfo[strtolower($tag)] .= $data;
}//end checking channel
else if($type == 2){
$itemInfo[$counter][strtolower($tag)] .= $data;
}//end checking for item
}//end checking tag
}//end cdata funct
function closing_element($xmlParser, $name){
global $tag, $type, $counter;
$tag = "";
if($name == "RESULT"){
$type = 0;
$counter++;
}
else if($name == "RESULTLIST"){
$type = 0;
}
}//end closing_element
$xmlParser = xml_parser_create();
xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, TRUE);
xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, TRUE);
xml_set_element_handler($xmlParser, "opening_element", "closing_element");
xml_set_character_data_handler($xmlParser, "c_data");
$fp = $file;
foreach($fp as $line){
if(!xml_parse($xmlParser, $line)){
die("Could not parse file.");
}
}
Can anyone shed some light?