Jump to content

How best to merge/compare 2 XML feeds


mortoau

Recommended Posts

I am importing two XML feeds into a database. Each feed has "odds" on sporting events.

 

The problem is each feed has different names of the same sporting event.

 

For example:

 

feed 1 describes an event as "Team A vs Team B"

feed 2 describes the same event as "TEAM A v TEAM B"

 

Do I need a mapping table to have a master event ID which knows feed 1 and feed 2's name of the event is actually the same?

 

So when I import the XML feed to get the lastest odds for every event I know how to match the different names of the same event in each feed?

Link to comment
https://forums.phpfreaks.com/topic/238749-how-best-to-mergecompare-2-xml-feeds/
Share on other sites

if the differences are just the 2 you described (uppercase/lowecase and the fact that one says 'v' and the other says 'vs'), then just for the sake of comparison you could convert them all to lowercase and do a replace of all 'vs'

str_replace(" vs "," v",$file_contents);

 

Of course, this is just a silly fix, and also depends on how you're importing the data (string or array). a unique id per event, as you said, would be much better and easier to identify.

 

 

To further complicate things is the placeholders can also be different. Feed1 calls the game "event" and feed2 calls the game "competition".

 

So the value and the placeholder tag are different but have the same meaning.

 

<feed1>
<event>Team A vs Team B</event>
</feed1>

<feed2>
<competition>TEAM A v TEAM B</competition>
</feed2>

you could also build little translation arrays. Meaning: all the possible words for each placeholder (depends really on how many there are, if they're only a few, this could work fine). Like:

 

$similar1 = array("event","competition","match","game");

 

then, when you grab a placeholder name, you search through the arrays looking for it. If you use position [0] as your default name, then you can easily translate them. If there are a lot, you can build a simple database with `defaultWord`,`similarWord` and just search through that.

 

again, not the best way to solve your problem, but it should work.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.