homepage Welcome to WebmasterWorld Guest from 54.161.214.221
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
XML Parsing
Can anyone find the fault with this code?
crounauer




msg:1541578
 4:47 pm on Feb 16, 2006 (gmt 0)

Hi,

I have done the script below and am trying to parse a feed from Laterooms. It is showing the county ID, but not the country name. Any suggestion?

Thanks,
Simon

<code>
<?php
$insideitem = false;
$tag = "";
$country_code = "";
$country_name = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $country_code, $country_name;
if ($insideitem) {
$tag = $name;
} elseif ($name == "COUNTRY") {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $country_code, $country_name;
print "". $country_code ."&nbsp;";
print "". $country_name ."<br>";
$country_code = "";
$country_name = "";
$insideitem = false;
}

print "<h2>COUNTRIES</h2>";

function characterData($parser, $data) {
global $insideitem, $tag, $country_code, $country_name;
if ($insideitem) {
switch ($tag) {
case "COUNTRY_CODE":
$country_code .= $data;
break;
case "COUNTRY_NAME":
$country_name .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://xml.laterooms.com/xml_ctry.php3?lang=eng","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 2048)) {
xml_parse($xml_parser, $data, feof($fp));
}
fclose($fp);
xml_parser_free($xml_parser);
?>
</code>

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved