0
votes

I'm beginning to use simplexml and I don't know what I'm doing wrong .. :(

I want to extract a xml from a url, I'm using the following code:

$xml = new SimpleXMLElement(file_get_contents($url));

And... print_r shows other object SimpleXML inside my array...It is correct? How can I read it?

SimpleXMLElement Object
(
    [action] => QUERY
    [response] => SUCCESS
    [responsedata] => SimpleXMLElement Object
        (
        )

)

Thanks a lot,

1
First of all put echo "<pre>"; before your print_r so that you can see exact array format in a better way. and put it here. - Neeraj Kumar
As floww said, Use simplexml_load_file instead! - Ma'moon Al-Akash
Yes, I try simplexml_load_file, and I get the same result: SimpleXMLElement Object ( [action] => QUERY [response] => SUCCESS [responsedata] => SimpleXMLElement Object ( ) ) - winkaneye

1 Answers

0
votes

SimpleXMLElement::__construct provides an optional (3rd) argument called data_is_url for cases like yours.

By default, data_is_url is FALSE. Use TRUE to specify that data is a path or URL to an XML document instead of string data.

You should try something like:

$xml = new SimpleXMLElement($url, 0, true);