Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [XML][PHP]Błąd function children() on a non-object podczas parsowania
mlody69
post
Post #1





Grupa: Zarejestrowani
Postów: 183
Pomógł: 0
Dołączył: 18.05.2009

Ostrzeżenie: (0%)
-----


Witam,
posiadam następujący kod:
  1. function List($campaign_id)
  2. {
  3. require 'config.php';
  4. $date = '2011-07-31';
  5. //$date = date('Y-m-d');
  6.  
  7. $ch = curl_init();
  8. $url = "https://{$settings['client_name']}.directtrack.com/apifleet/rest/{$settings['client_name']}/".
  9. "{$settings['access_id']}/leadDetail/campaign/{$campaign_id}/".$date."/";
  10. $headers[] = "Authorization: Basic ".base64_encode($settings['username'].":".$settings['password']);
  11.  
  12. // Initiate the REST call via curl
  13. $ch = curl_init($url);
  14.  
  15. // Set the HTTP method to GET
  16. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  17. // Add the headers defined above
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. // Don't return headers
  20. curl_setopt($ch, CURLOPT_HEADER, false);
  21. // Return data after call is made
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  23.  
  24. $response = curl_exec($ch);
  25. curl_close($ch);
  26.  
  27. $xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
  28.  
  29. foreach($xml->children() as $lead)
  30. {
  31. $a = explode('/',$lead['location']);
  32. $return[] = array_pop($a);
  33. }
  34. if(isset($return))
  35. return $return;
  36. else
  37. return false;
  38. }

Skrypt zwraca taki bład:
Cytat
Fatal error: Call to a member function children() on a non-object in
. Próbowałem już wszystkiego i nadal nie wiem dlaczego tak się dzieje.

Ten post edytował mlody69 4.08.2012, 14:16:09
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
Crozin
post
Post #2





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Komunikat błędu jest bardzo jasny - zmienna $xml nie jest obiektem. Gdzie jest ustalana wartość zmiennej $xml? Linijkę wcześniej jako wartość zwrócona przez simplexml_load_string.
I teraz patrzysz do manuala na to co może zwrócić ta funkcja...
Go to the top of the page
+Quote Post
mlody69
post
Post #3





Grupa: Zarejestrowani
Postów: 183
Pomógł: 0
Dołączył: 18.05.2009

Ostrzeżenie: (0%)
-----


Zwraca obiekt. Wywołanie kodu var_dump($xml) mówi "bool(false)" czyli muszę szukać problemu jeszcze wcześniej.
Go to the top of the page
+Quote Post
Crozin
post
Post #4





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Litości...
Cytat("http://php.net/simplexml_load_string#refsect1-function.simplexml-load-string-returnvalues")
Return Values
Returns an object of class SimpleXMLElement with properties containing the data held within the xml document, or FALSE on failure.


Ten post edytował Crozin 4.08.2012, 14:42:33
Go to the top of the page
+Quote Post
mlody69
post
Post #5





Grupa: Zarejestrowani
Postów: 183
Pomógł: 0
Dołączył: 18.05.2009

Ostrzeżenie: (0%)
-----


Miałem na myśli, że w przypadku gdy nie ma problemów zwraca obiekt lub zwraca FALSE tak jak u mnie. Wrzuciłem skrypt na inny serwer (testowałem na localhoście) i już działa, więcj dziękuje.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 12:25