SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict JerXs's Avatar
    Join Date
    Nov 2005
    Location
    Wilkes-Barre, PA
    Posts
    347
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Simple Shopping.com XML Parsing Scipt

    I am trying to build a simple parsing program for shopping.com XML feeds. Ive tried numerous parsing programs out there, though none will parse shopping.com's feeds for some reason. Most see no XML in the requested documents.

    Anyway I have very limited PHP knowledge. I tried learning a year or so ago, got discouraged and gave it up to learn more simple scripting/programming (css/xhtml/some xml), so please bear with me. What I have so far is few lines of code put together from info found on php.net (SimpleXML) and another source that I can not get to work.

    Ive tried numerous things and have not gotten anything to work, nothing but errors! Trying to keep it really simple for now. Ill build on it as I learn and understand.

    So this is what I have as of right now.....

    Code:
    <?php 
    
    $xmlSource = file_get_contents('http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword=nikon');
    $xmlDoc = SimpleXMLElement($xmlSource);
    
    foreach($xmlDoc->categories->category->items->product) {
    var_dump($xmlDoc) 
    }	 
    
    ?>
    My logic; $xmlSource, source of the feed, or xml, $xmlDoc is source brought in for simpleXML to compile / parse, foreach to indicate what depth/level or info to parse or work with, finally var_dump to finalize thing and get end result.

    Obviously my logic is wrong, so Im hoping someone can tell me where and help me fix and understand my errors.

    Hope you can help, Jer

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Maybe this will help.
    PHP Code:
    <?php
    $response 
    = new SimpleXMLElement(
        
    'http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword=nikon',
        
    null,
        
    true
    );
    foreach(
    $response->categories->category->items->product as $product)
    {
        
    printf(
            
    '
            <h3>%1$s</h3>
            <p>%2$s</p>
            <a href="%3$s" alt="%1$s">More...</a>
            '
    ,
            
    $product->name,
            
    $product->shortDescription,
            
    $product->productOffersURL
        
    );
    }
    /*
        <h3>Nikon CoolPix S630 Digital Camera</h3>
        <p>12.7 Megapixel, Compact Camera, 2.7 in. LCD Screen, 7x Optical Zoom, With Video Capability, Weight: 0.31 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-CoolPix-S630~linkin_id-7000610" alt="Nikon CoolPix S630 Digital Camera">More...</a>
        
        <h3>Nikon COOLPIX S220 Digital Camera</h3>
        <p>10.7 Megapixel, Ultra-Compact Camera, 2.5 in. LCD Screen, 3x Optical Zoom, With Video Capability, Weight: 0.22 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Nikon-Coolpix-S220-Aqua-Green-10-0MP-3x-Optical-Zoom-2-5-LCD~linkin_id-7000610" alt="Nikon COOLPIX S220 Digital Camera">More...</a>
        
        <h3>Nikon Coolpix S230 Digital Camera</h3>
        <p>10.34 Megapixel, Compact Camera, 3 in. LCD Screen, 3x Optical Zoom, With Video Capability, Weight: 0.26 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Coolpix-S230~linkin_id-7000610" alt="Nikon Coolpix S230 Digital Camera">More...</a>
        
        <h3>Nikon COOLPIX S70 Digital Camera</h3>
        <p>12.39 Megapixel, Compact Camera, 3.5 in. LCD Screen, 5x Optical Zoom, With High Definition Video, Weight: 0.31 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-COOLPIX-S70~linkin_id-7000610" alt="Nikon COOLPIX S70 Digital Camera">More...</a>

        <h3>Nikon Coolpix P90 Digital Camera</h3>
        <p>12.1 Megapixel, Point and Shoot Camera, 3 in. LCD Screen, 24x Optical Zoom, With Video Capability, Weight: 1.01 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Coolpix-P90~linkin_id-7000610" alt="Nikon Coolpix P90 Digital Camera">More...</a>

    */
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict JerXs's Avatar
    Join Date
    Nov 2005
    Location
    Wilkes-Barre, PA
    Posts
    347
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I try running the above I get a series of warnings and errors, the first is....

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: URL file-access is disabled in the server configuration in
    Which I believe is setting off the other four that follow.

    Looks like something server side. I will be using this little parser on a site that I have hosted at MediaTemple. Do you know if the setting can be changed with shared / grid hoisting? Maybe a custom php.ini file or something. Or is there a way using php to get around the server error /warning?

    Thanks again Jer

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Chances are the allow_url_fopen directive has been set to false, AFAIK, this cannot be overridden at runtime.

    There's always cURL.

    PHP Code:
    <?php
    $handle 
    curl_init('http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword=nikon');
    curl_setopt_array($handle, array(
        
    CURLOPT_RETURNTRANSFER    => true
    ));

    $data curl_exec($handle);
    $response = new SimpleXMLElement($data);
    foreach(
    $response->categories->category->items->product as $product)
    {
        
    printf(
            
    '
            <h3>%1$s</h3>
            <p>%2$s</p>
            <a href="%3$s" alt="%1$s">More...</a>
            '
    ,
            
    $product->name,
            
    $product->shortDescription,
            
    $product->productOffersURL
        
    );
    }
    /*
        <h3>Nikon CoolPix S630 Digital Camera</h3>
        <p>12.7 Megapixel, Compact Camera, 2.7 in. LCD Screen, 7x Optical Zoom, With Video Capability, Weight: 0.31 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-CoolPix-S630~linkin_id-7000610" alt="Nikon CoolPix S630 Digital Camera">More...</a>
        
        <h3>Nikon COOLPIX S220 Digital Camera</h3>
        <p>10.7 Megapixel, Ultra-Compact Camera, 2.5 in. LCD Screen, 3x Optical Zoom, With Video Capability, Weight: 0.22 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Nikon-Coolpix-S220-Aqua-Green-10-0MP-3x-Optical-Zoom-2-5-LCD~linkin_id-7000610" alt="Nikon COOLPIX S220 Digital Camera">More...</a>
        
        <h3>Nikon Coolpix S230 Digital Camera</h3>
        <p>10.34 Megapixel, Compact Camera, 3 in. LCD Screen, 3x Optical Zoom, With Video Capability, Weight: 0.26 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Coolpix-S230~linkin_id-7000610" alt="Nikon Coolpix S230 Digital Camera">More...</a>
        
        <h3>Nikon COOLPIX S70 Digital Camera</h3>
        <p>12.39 Megapixel, Compact Camera, 3.5 in. LCD Screen, 5x Optical Zoom, With High Definition Video, Weight: 0.31 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-COOLPIX-S70~linkin_id-7000610" alt="Nikon COOLPIX S70 Digital Camera">More...</a>

        <h3>Nikon Coolpix P90 Digital Camera</h3>
        <p>12.1 Megapixel, Point and Shoot Camera, 3 in. LCD Screen, 24x Optical Zoom, With Video Capability, Weight: 1.01 lb.</p>
        <a href="http://www.shopping.com/xPO-Nikon-Coolpix-P90~linkin_id-7000610" alt="Nikon Coolpix P90 Digital Camera">More...</a>
    */
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Addict JerXs's Avatar
    Join Date
    Nov 2005
    Location
    Wilkes-Barre, PA
    Posts
    347
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice, that works.... I should be able to build off of that.. Thanks for the help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •