Web Analytics Made Easy -
StatCounter 'DOCUMENT IS EMPTY' with simplexml_load_file - CodingForum


No announcement yet.

'DOCUMENT IS EMPTY' with simplexml_load_file

  • Filter
  • Time
  • Show
Clear All
new posts

  • 'DOCUMENT IS EMPTY' with simplexml_load_file

    Hi All,

    im using simplexml_load_file() to grab an xml file, when i go directly to the XML it is fine but the code seems to load it blank - im actually using ebay's tutorial:


    error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging

    // API request variables
    $endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call
    $version = '1.0.0'; // API version supported by your application
    $appid = '"!REMOVED APP ID!'; // Replace with your own AppID
    $globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE)
    $query = 'harry potter'; // You may want to supply your own query
    $safequery = urlencode($query); // Make the query URL-friendly

    // Construct the findItemsByKeywords HTTP GET call
    $apicall = "$endpoint?";
    $apicall .= "OPERATION-NAME=findItemsByKeywords";
    $apicall .= "&SERVICE-VERSION=$version";
    $apicall .= "&SECURITY-APPNAME=$appid";
    $apicall .= "&GLOBAL-ID=$globalid";
    $apicall .= "&keywords=$safequery";
    $apicall .= "&paginationInput.entriesPerPage=2";

    // Load the call and capture the document returned by eBay API
    $resp = simplexml_load_file($apicall);

    // Check to see if the request was successful, else print an error
    $response1 = $resp->ack;
    if ($resp->ack == "") {
    $results = '';
    // If the response was loaded, parse it and build links
    foreach($resp->searchResult->item as $item) {
    $pic = $item->galleryURL;
    $link = $item->viewItemURL;
    $title = $item->title;

    // For each SearchResultItem node, build a link and append it to $results
    $results .= "<tr><td><img src=\"$pic\"></td><td><a href=\"$link\">$title</a></td></tr>";
    // If the response does not indicate 'Success,' print an error
    else {
    $results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
    $results .= "AppID for the Production environment.</h3>";

    <!-- Build the HTML page with values from the call response -->
    <title>eBay Search Results for <?php echo $query; ?></title>
    <style type="text/css">body { font-family: arial,sans-serif;} </style>

    <h1>eBay Search Results for <?php echo $query; ?></h1>

    <?php echo $results; ?>


  • #2
    for creating an URL query, better use http_build_query().

    what do you have set allow_url_fopen to?

    since you want to pass an URL, why not using the Simple XML constructor for that, it has a dedicated option for using URLs? (see PHP: SimpleXMLElement::__construct - Manual)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer