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 );
6
  • nop, not this what i meant :(, i tried that Commented Apr 14, 2014 at 11:12
  • suggest you var dump $result to make sure you are getting the full XML you expect. Commented Apr 14, 2014 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 ? Commented Apr 14, 2014 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. Commented Apr 14, 2014 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. Commented Apr 22, 2014 at 14:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.