Jump to content

can't seem to parse xml


dezkit

Recommended Posts

hey guys i got this code:

<?php 

$file = "http://steamcommunity.com/id/itzdezkit/?xml=1"; 

function contents($parser, $data){ 
    echo $data; 
} 

function startTag($parser, $data){ 
    echo "<b>"; 
} 

function endTag($parser, $data){ 
    echo "</b><br />"; 
} 

$xml_parser = xml_parser_create(); 
xml_set_element_handler($xml_parser, "steamID", "steamID"); 

xml_set_character_data_handler($xml_parser, "contents"); 

$fp = fopen($file, "r"); 

$data = fread($fp, 80000); 

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); 

?>

 

which doesn't work and gives me this error:

Warning: xml_parse() [function.xml-parse]: Unable to call handler steamID() in /home/dima1989/public_html/testz.php on line 28

 

what im trying to do: get all the inforamtion between <steamID> and </steamID>

how would i be able to fix this? thank you. also i would like to set the parsed infrmation into a variable.

Link to comment
Share on other sites

This is the definition of the function you are using -

bool xml_set_element_handler ( resource $parser , callback $start_element_handler , callback $end_element_handler )

 

This is your usage of it -

xml_set_element_handler($xml_parser, "steamID", "steamID");

 

Did you put your start and end element handlers in as the second and third parameters?

 

i would like to set the parsed information into a variable

 

Because the callback functions are called by the parser and cannot return values to your program, you would need to use this inside of a class/OOP where you can set class variables inside of the callback functions in order to make the parsed information available to other code in your program.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.