tags:

views:

92

answers:

2

i have a list of xml documents that i want to extract data from and add to my database- which way is the best in php?

example documents are

http://xml.gamebookers.com/sports/football.xml http://www.bet-at-home.com/oddxml.aspx?lang=en

I want to extract the odds of a the soccer teams, the odds of them winning and match them with the fixtures i have in my database- which way would be the best way/function to do this?

+8  A: 

Go for SimpleXML (http://php.net/simplexml).

You can navigate through your files very easily and it supports XPath for even more intuitive XML navigation.

A basic example:

<?php
$xml = simplexml_load_file('http://xml.gamebookers.com/sports/football.xml');
foreach ($xml->partybets->event as $event)
{
  echo "<h3>", $event->eventName, "</h3>";
  echo "<p><strong>Odd</strong>: ", $event->odd1, "</p>";
}
?>
Ruud v A
+1  A: 

You might find

SimpleXml

or

phpDom

interessting. Simple XML is, as the name implies, pretty simple. But as as longs as you just want to iterate through a structure of data it's the right thing for the job... dom is the choice of you need to write xml too.

KB22