/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] parsing xml using php

i am trying to make a script that gets feeds from an third party site and i need to parse the information and add it to a database on my site for user interaction.

i would like some help in the form of you telling me where to read on how to do this, or an example.

i would need to break all the info down, and store it into the database once daily, and this seems like it should be really easy once you break down the xml file into variables.

any help would be greatly appreciated.

here is a sample xml

[CODE]<odds>
&#8722;
<entry>
<date_time>05-18-09 7:05 PM</date_time>
<awayrotationnumber>301</awayrotationnumber>
<awayteam>Pirates (Pittsburgh)</awayteam>
<awaymoney>-110</awaymoney>
<awayline>off</awayline>
<awaytotal>o10(-105)</awaytotal>
<homerotationnumber>302</homerotationnumber>
<hometeam>Nationals (Washington)</hometeam>
<homemoney>-110</homemoney>
<homeline>off</homeline>
<hometotal>u10(-115)
</hometotal>
</entry>
&#8722;
<entry>
<date_time>05-18-09 7:10 PM</date_time>
<awayrotationnumber>303</awayrotationnumber>
<awayteam>Diamondbacks (Arizona)</awayteam>
<awaymoney>-130</awaymoney>
<awayline>off</awayline>
<awaytotal>o8.5(Even)</awaytotal>
<homerotationnumber>304</homerotationnumber>
<hometeam>Marlins (Florida)</hometeam>
<homemoney>+110</homemoney>
<homeline>off</homeline>
<hometotal>u8.5(-120)
</hometotal>
</entry>[/CODE]

ideally each of those would become a var inside a loop which inserts the data into the database. please point me in the right direction. thank you.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tracknutMay 18.2009 — Take a read thru the SimpleXML specs. It's not called "simple" for nothing...

Dave
Copy linkTweet thisAlerts:
@benifactorauthorMay 18.2009 — ok, so i have the xml file as an object, could you point me in the right direction for messing with objects? specifically i need to break the data up, maybe in a loop and then send it to the database.

with this code, i have returned the data to the screen:

[code=php]$xml = simplexml_load_file('http://linesmaker.com/xml/592.xml', 'SimpleXMLElement',LIBXML_NOCDATA);


print_r($xml);[/code]


all im looking for is the right direction... thanks
Copy linkTweet thisAlerts:
@benifactorauthorMay 18.2009 — i got it with foreach(). thanks for the right direction!
×

Success!

Help @benifactor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...