CodeIgniter Forums
How to parse an XML file from a url and add its data in a database? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to parse an XML file from a url and add its data in a database? (/thread-33404.html)



How to parse an XML file from a url and add its data in a database? - El Forum - 08-25-2010

[eluser]GeorgiosK[/eluser]
I can parse an .xml file from a url but there are some complications.
The output it's not formatted so it's hard to read it and I am having a hard time to put the data in my database. The code is below...
Code:
$url='http://website.com/api/item.xml?type_ids=34,35&key=123456';
        $xmlstr = simplexml_load_file($url);  
        $data['ore_market']=print_r($xmlstr);
        $this->load->view('ore_marketeerview',$data);

I know that 'xmlrpc' library can help me parse the xml file but I don't know what to put in method().

Code:
$url='http://website.com/api/item.xml?type_ids=34,35&key=123456';
$this->xmlrpc->server($url, 80);
$this->xmlrpc->method(???);

And since I pass the parameters I want in $url do I need to specify something in $request?
Code:
$request = array('My Photoblog', 'http://www.my-site.com/photoblog/');

$this->xmlrpc->request($request);

Is there a library to help me manipulate the xml output afterwards and help me insert its data in a database?


How to parse an XML file from a url and add its data in a database? - El Forum - 08-25-2010

[eluser]bretticus[/eluser]
XML-RPC is meant more as a system for a Web service (think SOAP or REST.) In other words, requests from the client will be interpreted as code calls on the server. The server will then return the results of the code ran. Not really what you are doing.

PHP has an excellent extension called SimpleXML. It basically maps an XML document to an object that is easy to traverse.

UPDATE

I see you are using SimpleXML already. My advice about XML-RPC still stands and you should follow the documentation for SimpleXML to parse it. See SimpleXML Examples.