Page 1 of 1
Parsing XML from URL (simpleXml)
Posted: Fri Apr 17, 2009 4:36 am
by basil_shine
I have to read xml file into my page and parse it.
Im going this way:
$url = '
http://www.developments-online.com/live ... mlfeed.asp';
$xml = simplexml_load_file($url);
But this one gives me errors of missing document. So i dont know what to do. Was trying to use threads, but it didnt work either.
I should use simpleXml.
Thank you.
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 17, 2009 4:47 am
by susrisha
1. The given url is not an xml file. its probably calling or echoing a code whose output is an xml.
2. so do a curl operation with return var set and load the data.
Code: Select all
//Example URL:
$URL="http://www.developments-online.com/live/resales/export/xmlfeed.asp";
//initiate the curl
$ch = curl_init();
//set the URL to the curl handle
curl_setopt($ch, CURLOPT_URL, $URL);
//ignore header
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$returned_variable =curl_exec($ch);
// close CURL resource, and free up system resources
curl_close($ch);
$xml = simplexml_load_string($returned_variable );
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 17, 2009 5:01 am
by requinix
susrisha wrote:1. The given url is not an xml file. its probably calling or echoing a code whose output is an xml.
Dunno what you're talking about. When I go there I get XML data.
And the code works well for me.
Code: Select all
<?php
$url = 'http://www.developments-online.com/live/resales/export/xmlfeed.asp';
$xml = simplexml_load_file($url);
print_r($xml);
Code: Select all
SimpleXMLElement Object
(
[resales_online] => SimpleXMLElement Object
(
[error_message] => Invalid Login Details - Access Denied
)
)
Well, relatively well.
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 17, 2009 5:34 am
by basil_shine
susrisha wrote:1. The given url is not an xml file. its probably calling or echoing a code whose output is an xml.
2. so do a curl operation with return var set and load the data.
Code: Select all
//Example URL:
$URL="http://www.developments-online.com/live/resales/export/xmlfeed.asp";
//initiate the curl
$ch = curl_init();
//set the URL to the curl handle
curl_setopt($ch, CURLOPT_URL, $URL);
//ignore header
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$returned_variable =curl_exec($ch);
// close CURL resource, and free up system resources
curl_close($ch);
$xml = simplexml_load_string($returned_variable );
This is great. Thank you very much. Couldn't find solution for this problem for a long time.
Now its working very well.
Re: Parsing XML from URL (simpleXml)
Posted: Mon Apr 20, 2009 12:50 am
by susrisha
@tasairis
there might be a problem with allow_url_fopen which is restricting the opening of those files.
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 24, 2009 1:59 am
by basil_shine
Rightn now i've tried to work with xml. But I'm having trouble picking the info out of the file. Could anyone please help?
It loads all xml right into the page. But i dont want it to load right in to it.
I just want to pick info.
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 24, 2009 4:19 am
by php_east
you already have the xml.
you can do whatever you want with it. what specific help do you need ?
the DOM XML defines how and what are available to you.
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 24, 2009 4:42 am
by viraj
you can pick information from the xml file by using these functions.
http://www.php.net/manual/en/ref.simplexml.php
Re: Parsing XML from URL (simpleXml)
Posted: Fri Apr 24, 2009 5:26 am
by basil_shine
Thank you for your replies. As i told you before, everything worked when i was loading xml from local file. These way i can't use simplexml_load_string and simplexml_load_file because these code returns all xml file and execute it right in to the page ignoring simplexml_load_...
I mean i want to take that xml and work with it, but i dont want it to show up in the browser window, just some info from it.
Code: Select all
$xml = simplexml_load_string($returned_variable );
echo $xml->feed_version; // just as an example of idea that i want from $xml
It returns all xml file instead of only $value of $xml->
Re: Parsing XML from URL (simpleXml)
Posted: Sun Apr 26, 2009 6:50 am
by php_east
at the risk of myself sounding really stupid, if you don't want to put out the xml in your browser,
why then do you echo it out ? just work with the var.