Welcome Guest, Not a member yet? Register   Sign In
How to parse an XML file from a url and add its data in a database?
#1

[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?
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB