1

When I'm trying to use simplexml_load_string it returns an array of "SIMPLE XML objects" with some "Empty" object attributes. Actually those attributes are not empty in the real XML output!

Do you have any suggestions?

    $url = "widgets.sportsevents365.com/data/tickets/v2.0/events/?q=cq,0,$sportType,$numOfDays&page=$page&perpage=$perpage";

    $ch = curl_init();     
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER ,array('Contect-Type:text/xml','application/xml') );        
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_USERPWD, "*****:*****");  
    $result = curl_exec($ch);  

    curl_close($ch);  


    $xmldata = simplexml_load_string($result);

    print_r( $xmldata );
hakre
  • 193,403
  • 52
  • 435
  • 836
Ibraheem
  • 160
  • 1
  • 11
  • nop, not this what i meant :(, i tried that – Ibraheem Apr 14 '14 at 11:12
  • suggest you var dump $result to make sure you are getting the full XML you expect. – edmondscommerce Apr 14 '14 at 11:13
  • oh i checked it , im getting values inside <![CDATA[ , then the simplexml_load_string is removig them, so how to catch those values ? – Ibraheem Apr 14 '14 at 11:25
  • PHP will never assume that a file path is a URL unless it starts with a proper protocol prefix. Seriously. Whatever, you do two entirely different tasks (download a remote a file + parse XML) but treat them as a whole. You need to do some basic debugging: if file downloads OK, the curl code is irrelevant. If it doesn't, the XML code is irrelevant. – Álvaro González Apr 14 '14 at 11:34
  • As you've discovered in your (now deleted) question, it is a good idea to assemble all the necessary information about a problem before asking. In the case of loading data into MySQL, it's worth saying if you are doing it in a console or a web application, how long it is taking, and what the reason for its failure is. Also, do check to see if the question has been asked before - that one almost certainly has. – halfer Apr 22 '14 at 14:41
  • Ok thx :) bro . I appreciate ur commment..and ur effort to keep Stackoverflow Usefull :) – Ibraheem Apr 22 '14 at 14:46

1 Answers1

1

From the comment...

im getting values inside <![CDATA[ , then the simplexml_load_string is removig them, so how to catch those values ?

You need to use the LIBXML_NOCDATA flag.

$xmldata = simplexml_load_string($result,LIBXML_NOCDATA);

Why to use LIBXML_NOCDATA ?

By using this flag it will merge the CDATA as text nodes.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126