how to read xml feed from the url

Discussion in 'PHP' started by macky_shak, May 15, 2009.

  1. #1
    hi,

    i have a link which shows a xml file

    https://api.trueknowledge.com/direct_answer?object_metadata=image128,wikipedia,official&question=What's+the+time+in+Chicago%3F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2

    i want to read this xml feed .

    plz suggest me the best way
     
    macky_shak, May 15, 2009 IP
  2. macky_shak

    macky_shak Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hey anyone suggest me ???
     
    macky_shak, May 15, 2009 IP
  3. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
  4. macky_shak

    macky_shak Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanx for ur reply

    but i have tryed this

    this is my code :

    <?php
    $xmlDoc = new DOMDocument();
    $xmlDoc->load('https://api.trueknowledge.com/direct_answer?object_metadata=image128,wikipedia,official &question=What%27s+the+time+in+Chicago%3F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2');
    
    $x = $xmlDoc->documentElement;
    foreach ($x->childNodes AS $item)
      {
    
    	  if($item->nodeName == 'tk:text_result')
      print $item->nodeValue . "<br />";
      }
    ?>
    PHP:
    but this is showing error:

    Warning: DOMDocument::load() [function.DOMDocument-load]: I/O warning : failed to load external entity "https://api.trueknowledge.com/direct_answer?object_metadata=image128%2Cwikipedia%2Cofficial%20&question=What%2527s%2Bthe%2Btime%2Bin%2BChicago%253F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2" in C:\xampp\htdocs\test\test.php on line 3

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test\test.php on line 6
     
    macky_shak, May 15, 2009 IP
  5. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    problem with the url encoding i think ... i tried without the apostrophe in " ... what's ... " eg "whats+the+time"

    like this:

     
    mallorcahp, May 15, 2009 IP
  6. fourfingers

    fourfingers Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I've never liked simplexml because I chose to get really good with preg_match_all() ... it handles xml, html & even excel spreadsheets. Likely it's not even installed on your server and that's why you're getting that error. What PHP version are you using?

    I would code something up and paste it here but I think showing you discussion + code is more beneficial.
     
    fourfingers, May 15, 2009 IP