Have an account? / Register

Forgot your password?

Forgot your username?

Results 1 to 7 of 7

Thread: How do i extract fields from this stdclass output

  1. #1
    Registered User toneharb's Avatar
    Join Date
    Dec 2003
    Location
    Chippenham Wiltshire
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do i extract fields from this stdclass output



    I called soap client for a web service (musicsalesdirect.com) and then called a WSDL function to retrieve all data records , but can't figure out how iterate through and get individual fields

    I tried xml->smdCatalogue->smdProduct[0]->smd_title;

    but nothing is displayed the only thing i can do is var dump or print_r the $xml which gives the following when i read the browser source code :

    ---------------------------------------------

    <p>stdClass Object<br />

    (<br />
    [ListCatalogueItems_DatasetResult] => stdClass Object<br />
    (<br />
    [schema] => <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="smdCatalogue"><xs:element name="smdCatalogue" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs :choice minOccurs="0" maxOccurs="unbounded"><xs:element name="smdProduct"><xs:complexType><xs:sequence><xs :element name="smd_product_id" type="xs:int" minOccurs="0"/><xs:element name="smd_song_id" type="xs:int" minOccurs="0"/><xs:element name="smd_title" type="xs:string" minOccurs="0"/><xs:element name="smd_catalogue_reference" type="xs:string" minOccurs="0"/><xs:element name="smd_filename" type="xs:string" minOccurs="0"/><xs:element name="smd_number_of_pages" type="xs:int" minOccurs="0"/><xs:element name="smd_price" type="xs:decimal" minOccurs="0"/><xs:element name="smd_arrangement" type="xs:string" minOccurs="0"/><xs:element name="Genres" type="xs:string" minOccurs="0"/><xs:element name="Artist" type="xs:string" minOccurs="0"/><xs:element name="smd_available_countries" type="xs:string" minOccurs="0"/><xs:element name="smd_release_date" type="xs:dateTime" minOccurs="0"/><xs:element name="smd_difficulty" type="xs:string" minOccurs="0"/><xs:element name="smd_keystage" type="xs:string" minOccurs="0"/><xs:element name="smd_language" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><br />
    [any] => <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><smdCatalogue xmlns=""><smdProduct diffgr:id="smdProduct1" msdata:rowOrder="0"><smd_product_id>84862</smd_product_id><smd_song_id>1991</smd_song_id><smd_title>The Beatles: Something</smd_title><smd_catalogue_reference>smd_h_000000000 0755504</smd_catalogue_reference><smd_filename>smd_h_000000 0000755504.sco</smd_filename><smd_number_of_pages>2</smd_number_of_pages><smd_price>2.2500</smd_price><smd_arrangement>PF::Piano</smd_arrangement><Genres>Rock, Pop</Genres><Artist>Beatles, The</Artist><smd_available_countries>AD, AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, AT, AU, AW, AZ, BA, BB, BD, BE, BF, BG, BH, BI, BJ, BM, BN, BO, BR, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM, CN, CO, CR, CU, CV, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES, ET, FI, FJ, FK, FM, FO, FR, GA, GB, GD, GE, GF, GG, GH, GI, GL, GM, GN, GP, GQ, GR, GS, GT, GU, GW, GY, HK, HM, HN, HR, HT, HU, ID, IE, IL, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MQ, MR, MS, MT, MU, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL, PM, PN, PR, PT, PW, PY, QA, RE, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SR, ST, SV, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TM, TN, TO, TR, TT, TV, TW, TZ, UA, UG, UM, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WF, WS, YE, YT, ZA, ZM, ZW</smd_available_countries><smd_release_date>2011-08-16T00:00:00+01:00</smd_release_date><smd_difficulty>Easy</smd_difficulty><smd_keystage/><smd_language>English</smd_language></smdProduct><smdProduct diffgr:id="smdProduct2" msdata:rowOrder="1"><smd_product_id>84863</smd_product_id><smd_song_id>204</smd_song_id><smd_title>The Beatles: Michelle</smd_title><smd_catalogue_reference>smd_h_000000000 0755503</smd_catalogue_reference><smd_filename>smd_h_000000 0000755503.sco</smd_filename><smd_number_of_pages>3</smd_number_of_pages><smd_price>2.2500</smd_price><smd_arrangement>PF::Piano</smd_arrangement><Genres>Rock, Pop</Genres><Artist>Beatles, The</Artist><smd_available_countries>AD, AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, AT, AU, AW, AZ, BA, BB, BD, BE, BF, BG, BH, BI, BJ, BM, BN, BO, BR, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM, CN, CO, CR, CU, CV, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES, ET, FI, FJ, FK, FM, FO, FR, GA, GB, GD, GE, GF, GG, GH, GI, GL, GM, GN, GP, GQ, GR, GS, GT, GU, GW, GY, HK, HM, HN, HR, HT, HU, ID, IE, IL, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MQ, MR, MS, MT, MU, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL, PM, PN, PR, PT, PW, PY, QA, RE, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SR, ST, SV, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TM, TN, TO, TR, TT, TV, TW, TZ, UA, UG, UM, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WF, WS, YE, YT, ZA, ZM, ZW</smd_available_countries><smd_release_date>2011-08-16T00:00:00+01:00</smd_release_date><smd_difficulty>Easy</smd_difficulty><smd_keystage/><smd_language>English</smd_language></smdProduct><smdProduct diffgr:id="smdProduct3" msdata:rowOrder="2"><smd_product_id>84864</smd_product_id><smd_song_id>1111</smd_song_id><smd_title>The Beatles: In My Life</smd_title><smd_catalogue_reference>smd_h_000000000 0755502</smd_catalogue_reference><smd_filename>smd_h_000000 0000755502.sco</smd_filename><smd_number_of_pages>2</smd_number_of_pages><smd_price>2.2500</smd_price><smd_arrangement>PF::Piano</smd_arrangement><Genres>Rock, Pop</Genres><Artist>Beatles, The</Artist><smd_available_countries>AD, AE, AF,.........
    --------------------------------------------------------------------

    The XML is apparently series of music titles , all i want to do is extract fields for each record , eg: title price catalogue number , but am stumped .

    Tried using Simplexml and other things but the problem is it expects either a string or file not a stdclass object , and casting gives error

    Was thinking of creating a file then using simplexml but don't know how to do that , and wonder if there is a way to access data as it is


  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    53
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Re: How do i extract fields from this stdclass output

    Can you post your SOAP request code?

  3. #3
    Registered User toneharb's Avatar
    Join Date
    Dec 2003
    Location
    Chippenham Wiltshire
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do i extract fields from this stdclass output

    You need to apply for standard account at sheetmusic direct , i have to keep password secret

    Thanks

    Code:
    $userName="secret";
    $password="secret";
    $client= new SoapClient("http://dw.sheetmusicdirect.com/smdwebsvc.asmx?wsdl");
    $startDate= date('Y-m-d', strtotime ('2011-08-17'));
    $endDate= date('Y-m-d', strtotime ('2011-08-18'));
    $guid="guid";

    if ($err){die('An error occured whilest the WSDL was being accessed: '.$err);
    }
    $params= array('username' => $userName,
    'password' => $password,
    'startDate' => $startDate,
    'endDate' => $endDate);

    $cat= $client->ListCatalogueItems_Dataset($params);
    print_r($cat);

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    53
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Re: How do i extract fields from this stdclass output

    This should do it:

    PHP Code:
    <?php

    $startDate  
    date'Y-m-d'strtotime'2011-08-17' ) );
    $endDate    date'Y-m-d'strtotime'2011-08-18' ) );
    $userName   "secret";
    $password   "secret";

    $options    = array(
        
    'cache_wsdl' => WSDL_CACHE_NONE,
        
    'soap_version' => SOAP_1_2,
        
    'trace' => true,
        
    'compression' => SOAP_COMPRESSION_ACCEPT SOAP_COMPRESSION_GZIP 5
    );

    $params     = array(
        
    'username' => $userName,
        
    'password' => $password,
        
    'startDate' => $startDate,
        
    'endDate' => $endDate 
    );

    $client = new SoapClient"http://dw.sheetmusicdirect.com/smdwebsvc.asmx?wsdl"$options );

    $object $client->ListCatalogueItems_Dataset$params );

    $response $client->__getLastResponse(); // get response as XML

    $xml simplexml_load_string($response);

    foreach (
    $xml->xpath('//smdProduct') as $product) {
        echo 
    '<b>Title: </b>'.$product->smd_title.'<br />';
        echo 
    '<b>Price: </b>'.$product->smd_price.'<br />';
        echo 
    '<b>Catalogue Number: </b>'.$product->smd_catalogue_reference.'<br />';
    }
    ?>

  5. #5
    Registered User toneharb's Avatar
    Join Date
    Dec 2003
    Location
    Chippenham Wiltshire
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do i extract fields from this stdclass output

    Many Thanks Michael

    I tried the above suggestion (thank you), i tried print_r $object to debug, and found the $options argument on New Client caused some problem (because without it $object was filled with XML data , whereas with it there was no data in the object)

    However with $optionsargument i get error "Fatal error: Call to a member function xpath() on a non-object"

    So i then did echo "response :" $reponse;

    Which was empty but have found trace has to be 1 for __GetLastReponse() to work , so $options needs to be for New Client, but as said above $object argument/parameter causes problem

  6. #6
    Registered User toneharb's Avatar
    Join Date
    Dec 2003
    Location
    Chippenham Wiltshire
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do i extract fields from this stdclass output

    Update ----- I took out the Compression part of options and it works!!!!

    Many - Many thanks for your help

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    53
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Re: How do i extract fields from this stdclass output

    No worries, I didn't have access to the web service so I was going a bit blind with my response! Good that it all works now though :-)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
To Top

SEO by vBSEO 3.6.1