Hi All,
I've been playing with parsing RDF/XML files using PHP (code snippet
below). However I'm having trouble trying to work out how to actually
format the results in an order. My source is in the form
Politicizing Science
http://slashdot.org/article.pl?sid=02/09/17/0349219
Now I could easily cope with it if it was link, title as I would just
print $title. However I just can't work out a way of
doing this, this way. My attempt so far is below (mostly debugging code)
function startElement($parser, $name, $attrs) {
global $depth,$type,$title,$url;
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
$type = $name;
$depth[$parser]++;
}
function stopElement($parser, $name) {
global $depth,$type,$title,$url;
$depth[$parser]--;
print "depth parse = $depth[$parser] and $title !! $url ";
}
function characterData($parser, $data) {
global $type,$title,$url;
if ($data)
{
switch ($type) {
case "ITEM":
case 'LINK':
$url=$data;
case "TITLE":
$title=$data;
}
}
}
$file="slashdot.rdf";
$fp= fopen($file,"r");
$parser=xml_parser_create();
xml_set_element_handler($parser,"startElement","stopElement");
xml_set_character_data_handler($parser,"characterData");
while ($data = fread($fp,4096))
xml_parse($parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),xml_get_current_line_number($parser)));
fclose($fp);
As you can see I'm trying to use global variables but I'm just really
unhappy with the quality of the code so any help would be appreciated.
Rgds
Rus foster
--
http://www.fsck.me.uk - Rant wibble wave
http://shells.fsck.me.uk - Hosting and stuff
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php