Parsing Data From NuSoap ?

Discussion in 'PHP' started by SunAndGames, Nov 9, 2005.

  1. #1
    I'm trying to write a SOAP application to AllPosters web services. I'm able to get a data response back from their server, but am unsure as to how to parse out the data they send me.

    Heres my code:

    <?php
    /* Set up our SOAP stuff */			
    include("nusoap.php");
    $soapclient = new soapclient('http://webservice.allposters.com/ProductInformationService.asmx');
    $soapclient->soap_defencoding = "UTF-8";
    $soapclient->namespaces = array(
    		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    		'xsd' => 'http://www.w3.org/2001/XMLSchema',
    		'soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
    );
    		
    $namespace = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService"; 
    $soapAction = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation";
    $WEBSITE_ID = '252003033';
    $searchterms = 'cars';
    
    $xml = array("APCSearchXml"=>"<![CDATA[<APC_Search_Query>".
    			"<WebSiteID>".$WEBSITE_ID."</WebSiteID>".
    			"<SearchText>".$searchterms ."</SearchText>".
    			"<ProductsPerPage>1</ProductsPerPage>".
    			"<SortOrder>p</SortOrder>".
    			"</APC_Search_Query>]]>"
    			);
    
    //get the feed
    $soapclient->charencoding = false;  //important!
    $response = $soapclient->call('GetProductInformation',$xml, $namespace, $soapAction,'','','rpc','literal');
    
    print_r ($response);
    
    echo '<h2>Response:</h2> <pre>' . $soapclient->response, ENT_QUOTES .'</pre>'; 
    
    ?>
    PHP:
    Here's the ouput from running my code:

     0  1563 1 1   988802  http://www.allposters.com/-sp/Ferrari-F1-2004_i988802_.htm?aid=252003033    232  350  76  115  36  24  Art Print  EUR  2400-5124_a.jpg  2400-5124.jpg  http://imagecache2.allposters.com/IMAGES/EUR/2400-5124_a.jpg  http://imagecache2.allposters.com/IMAGES/EUR/2400-5124.jpg  Y  http://affiliates.allposters.com/link/redirect.asp?item=988802&event=Mounted&AID=252003033&PSTID=1&LTID=5&lang=1  Y  http://affiliates.allposters.com/link/redirect.asp?item=988802&event=Framed&AID=252003033&PSTID=1&LTID=5&lang=1  N  12.0000  13.9900  54  2004-10-04T11:39:00.0000000-07:00  1563
    Response:
    
    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.0
    Date: Wed, 09 Nov 2005 15:14:09 GMT
    X-Powered-By: ASP.NET
    Connection: keep-alive
    X-AspNet-Version: 1.1.4322
    Cache-Control: private, max-age=0
    Content-Type: text/xml; charset=utf-8
    Content-Length: 2704
    Set-Cookie: NSC_XfcTfswjdf_80=0a5183270050;path=/
    
    <APC_Search_Results>
       <StatusCode>0</StatusCode>
       <Search_Result>
    <Total_No_Of_Products>1563</Total_No_Of_Products>
    <No_Of_Products_In_Current_Page>1</No_Of_Products_In_Current_Page>
    <Current_PageNumber>1</Current_PageNumber>
    <Products>
      <ProductInformation>
        <ProductNumber>988802</ProductNumber>
        <ProductLink>http://www.allposters.com/-sp/Ferrari-F1-2004_i988802_.htm?aid=252003033</ProductLink>
        <Title>Ferrari F1 - 2004</Title>
        <Artist />
        <ArtistLink />
        <ImageHeight>232</ImageHeight>
        <ImageWidth>350</ImageWidth>
        <ThumbnailHeight>76</ThumbnailHeight>
        <ThumbnailWidth>115</ThumbnailWidth>
        <ProductHeight>36</ProductHeight>
        <ProductWidth>24</ProductWidth>
        <ProductType>Art Print</ProductType>
        <Directory>EUR</Directory>
        <ThumbnailFileName>2400-5124_a.jpg</ThumbnailFileName>
        <ImageFileName>2400-5124.jpg</ImageFileName>
        <ThumbnailURL>http://imagecache2.allposters.com/IMAGES/EUR/2400-5124_a.jpg</ThumbnailURL>
        <ImageURL>http://imagecache2.allposters.com/IMAGES/EUR/2400-5124.jpg</ImageURL>
        <CanBeMounted>Y</CanBeMounted>
        <MountedLink>http://affiliates.allposters.com/link/redirect.asp?item=988802&amp;event=Mounted&amp;AID=252003033&amp;PSTID=1&amp;LTID=5&amp;lang=1</MountedLink>
        <CanBeFramed>Y</CanBeFramed>
        <FramedLink>http://affiliates.allposters.com/link/redirect.asp?item=988802&amp;event=Framed&amp;AID=252003033&amp;PSTID=1&amp;LTID=5&amp;lang=1</FramedLink>
        <CanBeQuickFramed>N</CanBeQuickFramed>
        <ListPrice>12.0000</ListPrice>
        <OurPrice>13.9900</OurPrice>
        <Rank>54</Rank>
        <DateAdded>2004-10-04T11:39:00.0000000-07:00</DateAdded>
        <MatchCount>1563</MatchCount>
      </ProductInformation>
    </Products>
    </Search_Result> 
    </APC_Search_Results>3
    Code (xml):
    When I just print_r the $response field, it displays all the data without the tags. $response is not an array, just a string variable. But, when I echo the $response field using <pre> formatting it shows all the tags associated with the data. I'm not sure I understand why.

    If $response was array data, I could implode it and use the parser functions in PHP to get at the data. I read a few posts about serialize / deserialize, but am not sure that is the answer. Any suggestions (code samples?) as to how I strip the data out of the $response field?

    Thanks,
     
    SunAndGames, Nov 9, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could you use some kind of xml/rss parsing script?
     
    dave487, Nov 9, 2005 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    print_r *does* echo the tags, but the browser, interpreting them as unknown HTML tags, doesn't display them.

    You can parse the result using php's xml parsing functions. I would basically discard anything before the first "<" which is where the xml starts, and then use the built-in php functions to extract the data. Have fun. :)
     
    exam, Nov 9, 2005 IP
  4. SunAndGames

    SunAndGames Well-Known Member

    Messages:
    135
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    118
    #4
    @exam . . . thanks very much, that helped. I didn't realize I had the tags all along, and could just go ahead and use the parser. So much to learn. Good rep coming your way.:)
     
    SunAndGames, Nov 9, 2005 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You're welcome. :)
     
    exam, Nov 9, 2005 IP
  6. raffuk

    raffuk Member

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #6
    This is 2010, 5 years after the last post. Im trying to use this script to access allposters.com api but no luck. Does anybody have it working in the actual version by any chance? Thanks.
     
    raffuk, Jan 19, 2010 IP