SHARE
TWEET

Untitled

a guest May 19th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function foundAnOpeningTag($parser,$tag)
  2. {
  3.     global $inOrigin, $inDestination;
  4.    
  5.     if($tag=="ORIGIN")
  6.     {
  7.         $inOrigin = true;
  8.     }
  9.     elseif($tag=="DESTINATION")
  10.     {
  11.         $inDestination = true;
  12.     }
  13. }
  14.  
  15. // Function to handle closing tags.
  16. function foundAClosingTag($parser,$tag)
  17. {
  18.     global $inOrigin, $inDestination;
  19.    
  20.     if($tag=="ORIGIN")
  21.     {
  22.         $inOrigin = false;
  23.     }
  24.     elseif($tag=="DESTINATION")
  25.     {
  26.         $inDestination = false;
  27.     }
  28. }
  29.  
  30. // Function to handle characters within tags.
  31. function foundSomeText($parser,$characters)
  32. {
  33.     global $inOrigin, $inDestination;
  34.     global $traindata;
  35.    
  36.     if($inOrigin)
  37.     {
  38.         $traindata["origins"][] = $characters;
  39.     }
  40.     elseif($inDestination)
  41.     {
  42.         $traindata["destinations"][] = $characters;
  43.     }
  44. }
  45.  
  46. // Parse the XML.
  47. $parser = xml_parser_create();
  48. xml_set_element_handler($parser, "foundAnOpeningTag","foundAClosingTag");
  49. xml_set_character_data_handler($parser, "foundSomeText");
  50. xml_parse($parser,$response);
  51. xml_parser_free($parser);
RAW Paste Data
Top