Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Php & Xml

  1. #1

    Php & Xml

    Ciao a tutti ragazzi!

    Ho un piccolo problema nel salvare un file xml in php.
    Ho il seguente codice:

    $query = 'iphone';

    $SafeQuery = urlencode($query);

    $endpoint = 'http://open.api.ebay.com/shopping';
    $responseEncoding = 'XML';

    $apicall = "$endpoint?callname=FindItems&version=517&appid=XX XXXX-XXXXX-XXXX&QueryKeywords=$SafeQuery&responseencoding=$re sponseEncoding";


    $resp = simplexml_load_file($apicall);

    In pratica sto usando le API di eBay. Lo script funziona alla grande ora però il file che estraggo tramite query se lo visualizzo con var_dump($resp) mi viene restituito nel formato di un oggetto simple_xml

    object(SimpleXMLElement)#1 (7) { ["Timestamp"]=> string(24) "2008-11-16T09:53:56.726Z" ["Ack"]=> string(7) "Success" ["Build"]=> string(28) "e589_core_Bundled_7495152_R1" ["Version"]=> string(3) "589" ["Item"]=> array(3) { [0]=> object(SimpleXMLElement)#2 (14) { ["ItemID"]=> string(12) "220308538912" ["BuyItNowAvailable"]=> string(4) "true" ["ConvertedBuyItNowPrice"]=> string(5) "18.55" ["EndTime"]=> string(24) "2008-11-16T09:54:00.000Z" ["ViewItemURLForNaturalSearch"]=> string(126) "http://cgi.ebay.com/GOLD-METAL-BACK-HOUSING-COVER-FOR-AU-APPLE-iPHONE-LENS_W0QQitemZ220308538912QQcategoryZ14418QQcmdZVi ewItem" ["ListingType"]=> string(7) "Chinese" ["PrimaryCategoryID"]=> string(5) "14418" ["PrimaryCategoryName"]=> string(45) "Phones:Mobile Accessories:Covers:Other Covers" ["BidCount"]=> string(1) "0" ["ConvertedCurrentPrice"]=> string(5) "16.56" ["ListingStatus"]=> string(6) "Active" ["TimeLeft"]=> string(4) "PT4S" ["Title"]=> string(55) "GOLD METAL BACK HOUSING COVER FOR AU APPLE iPHONE +LENS" ["ShippingCostSummary"]=> object(SimpleXMLElement)#5 (2) { ["ShippingServiceCost"]=> string(5) "11.26" ["ShippingType"]=> string(4) "Flat" } } [1]=> object(SimpleXMLElement)#3 (12) { ["ItemID"]=> string(12) "110311877113" ["EndTime"]=> string(24) "2008-11-16T09:54:01.000Z" ["ViewItemURLForNaturalSearch"]=> string(127) "http://cgi.ebay.com/Car-FM-Transmitter-Charger-REMOTE-for-iPhone-iPod-Touch_W0QQitemZ110311877113QQcategoryZ86541QQcmdZV iewItem" ["ListingType"]=> string(14) "FixedPriceItem" ["GalleryURL"]=> string(57) "http://thumbs2.ebaystatic.com/pict/1103118771138080_1.jpg" ["PrimaryCategoryID"]=> string(5) "86541" ["PrimaryCategoryName"]=> string(54) "Electronics:MP3, Digital Accessories:Other Accessories" ["ConvertedCurrentPrice"]=> string(5) "11.26" ["ListingStatus"]=> string(6) "Active" ["TimeLeft"]=> string(4) "PT5S" ["Title"]=> string(55) "Car FM Transmitter/Charger/REMOTE for iPhone/iPod Touch" ["ShippingCostSummary"]=> object(SimpleXMLElement)#6 (2) { ["ShippingServiceCost"]=> string(4) "7.28" ["ShippingType"]=> string(4) "Flat" } } [2]=> object(SimpleXMLElement)#4 (13) { ["ItemID"]=> string(12) "130268821456" ["EndTime"]=> string(24) "2008-11-16T09:55:13.000Z" ["ViewItemURLForNaturalSearch"]=> string(127) "http://cgi.ebay.com/unlock-3G-iPhone-turbosim-turbo-sim-card-no-cut-2-1-new_W0QQitemZ130268821456QQcategoryZ29778QQcmdZVie wItem" ["ListingType"]=> string(7) "Chinese" ["GalleryURL"]=> string(57) "http://thumbs2.ebaystatic.com/pict/1302688214568080_1.jpg" ["PrimaryCategoryID"]=> string(5) "29778" ["PrimaryCategoryName"]=> string(46) "Cell Phones & PDAs:Phone & SIM Cards:SIM Cards" ["BidCount"]=> string(1) "0" ["ConvertedCurrentPrice"]=> string(4) "0.99" ["ListingStatus"]=> string(6) "Active" ["TimeLeft"]=> string(7) "PT1M17S" ["Title"]=> string(55) "unlock 3G iPhone turbosim turbo sim card no cut 2.1 new" ["ShippingCostSummary"]=> object(SimpleXMLElement)#7 (2) { ["ShippingServiceCost"]=> string(4) "9.99" ["ShippingType"]=> string(4) "Flat" } } } ["TotalItems"]=> string(5) "67785" ["ItemSearchURL"]=> string(72) "http://search.ebay.com/ws/search/SaleSearch?fsoo=1&fsop=1&satitle=iphone" }

    e io lo vorrei salvare come XML puro. Mi sapreste aiutare? Vi ringrazio
    Buona domenica a tutti

  2. #2
    Invece di simplexml_load_file(), utilizza file_get_contents() (o uno dei tanti altri metodi disponibili per effettuare una richiesta HTTP).

  3. #3
    Grazie mille per il suggerimento.
    Ho provato echo file_get_contents($apicall) e mi visualizza questo:

    2008-11-16T11:08:03.224Z Success e591_core_Bundled_7560815_R1 591 270303330486 true 15.99 2008-11-16T11:08:32.000Z http://cgi.ebay.com/Belkin-Sports-Ar...QQcmdZViewItem Chinese http://thumbs1.ebaystatic.com/pict/2...04868080_1.jpg 20336 Cell Phones & PDAs:Cell Phone & PDA Accessories 0 9.99 Active PT29S 0.0 Flat 260315333715 2008-11-16T11:08:44.000Z http://cgi.ebay.com/OZ-Crystal-Case-...QQcmdZViewItem FixedPriceItem http://thumbs1.ebaystatic.com/pict/2...37158080_1.jpg 161656 Phones:Mobile Accessories:Cases:Apple iPhone 1.05 Active PT41S 5.1 Flat 160298463162 2008-11-16T11:09:00.000Z http://cgi.ebay.com/Silicon-Case-Pro...QQcmdZViewItem FixedPriceItem http://thumbs1.ebaystatic.com/pict/1...31628080_1.jpg 20336 Cell Phones & PDAs:Cell Phone & PDA Accessories 3.68 Active PT57S 0.0 Flat 67838 http://search.ebay.com/ws/search/Sal...satitle=iphone

    Mi servirebbe salvare il tutto in un file XML. Come posso fare?

  4. #4
    Guarda che file_get_contents() ti permette di ottenere TUTTO l'XML.
    Se poi devi salvarlo in un file, utilizza file_put_contents() oppure fopen etc.

  5. #5
    OK!!!Funziona alla grande! Ti ringrazio ancora per il tuo aiuto. Riporto di seguito il codice che ho usato e il risultato nel caso servisse a qualcun'altro:

    file_put_contents('resultXML.xml', file_get_contents($apicall));

    Risultato:

    <?xml version="1.0" encoding="UTF-8"?> <FindItemsResponse xmlns="urn:ebay:apis:eBLBaseComponents"> <Timestamp>2008-11-16T11:24:42.377Z</Timestamp> <Ack>Success</Ack> <Build>e591_core_Bundled_7560815_R1</Build> <Version>591</Version> <Item> <ItemID>360107581823</ItemID> <BuyItNowAvailable>true</BuyItNowAvailable> <ConvertedBuyItNowPrice currencyID="USD">7.99</ConvertedBuyItNowPrice> <EndTime>2008-11-16T11:24:47.000Z</EndTime> <ViewItemURLForNaturalSearch>http://cgi.ebay.com/Car-Holder-Mount...QQcmdZViewItem</ViewItemURLForNaturalSearch> <ListingType>Chinese</ListingType> <GalleryURL>http://thumbs3.ebaystatic.com/pict/3...18238080_1.jpg</GalleryURL> <PrimaryCategoryID>20336</PrimaryCategoryID> <PrimaryCategoryName>Cell Phones &amp; PDAs:Cell Phone &amp; PDA Accessories</PrimaryCategoryName> <BidCount>0</BidCount> <ConvertedCurrentPrice currencyID="USD">7.0</ConvertedCurrentPrice> <ListingStatus>Active</ListingStatus> <TimeLeft>PT5S</TimeLeft> <Title>Car Holder Mount + Charger for Apple iPhone 3G 8GB 16GB</Title> <ShippingCostSummary> <ShippingServiceCost currencyID="USD">4.0</ShippingServiceCost> <ShippingType>Flat</ShippingType> </ShippingCostSummary> </Item> <Item> <ItemID>370112572676</ItemID> <EndTime>2008-11-16T11:26:38.000Z</EndTime> <ViewItemURLForNaturalSearch>http://cgi.ebay.com/Top-Class-Crysta...QQcmdZViewItem</ViewItemURLForNaturalSearch> <ListingType>FixedPriceItem</ListingType> <GalleryURL>http://thumbs3.ebaystatic.com/pict/3...26768080_1.jpg</GalleryURL> <PrimaryCategoryID>118182</PrimaryCategoryID> <PrimaryCategoryName>Electronics:MP3, Digital Accessories:Cases:For Apple iPod</PrimaryCategoryName> <ConvertedCurrentPrice currencyID="USD">1.98</ConvertedCurrentPrice> <ListingStatus>Active</ListingStatus> <TimeLeft>PT1M56S</TimeLeft> <Title>Top-Class Crystal case apple iphone 3G 8GB 16GB 8G 16G</Title> <ShippingCostSummary> <ShippingServiceCost currencyID="USD">1.99</ShippingServiceCost> <ShippingType>Flat</ShippingType> </ShippingCostSummary> </Item> <Item> <ItemID>370112572683</ItemID> <EndTime>2008-11-16T11:26:38.000Z</EndTime> <ViewItemURLForNaturalSearch>http://cgi.ebay.com/USB-DATA-CABLE-i...QQcmdZViewItem</ViewItemURLForNaturalSearch> <ListingType>FixedPriceItem</ListingType> <GalleryURL>http://thumbs1.ebaystatic.com/pict/3...26838080_1.jpg</GalleryURL> <PrimaryCategoryID>79877</PrimaryCategoryID> <PrimaryCategoryName>Electronics:MP3, Digital Accessories:Cables, Remote Controls:For Apple iPod</PrimaryCategoryName> <ConvertedCurrentPrice currencyID="USD">3.31</ConvertedCurrentPrice> <ListingStatus>Active</ListingStatus> <TimeLeft>PT1M56S</TimeLeft> <Title>USB DATA CABLE ipod classic itouch iphone NANO Video AU</Title> <ShippingCostSummary> <ShippingServiceCost currencyID="USD">1.99</ShippingServiceCost> <ShippingType>Flat</ShippingType> </ShippingCostSummary> </Item> <TotalItems>67853</TotalItems> <ItemSearchURL>http://search.ebay.com/ws/search/Sal...satitle=iphone</ItemSearchURL> </FindItemsResponse>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.