Jump to content

New to XML please help


unplugged_web

Recommended Posts

Is it possible to have an xml continually regenerate itself? I have a php file that was built by another company (it's an outside company that has nothing to do with my company). When I go the the php file an xml file is automatically generated, but I wanted to know if it is possible to save this xml file and have it still updating itself? Also the generated xml file has three blank lines at the top of the page, how do I remove those when I can't access the php file?The url for the php file is: http://stats.probability.tv/feed.php?key=<MY KEY>, but <MY KEY> is the password for the account. I really need to sort this out as soon as possible so would be grateful for any help.I've read lots of tutorials, but none of them seem to tell me how to save the xml file and then have it update itself.Thanks for your help.Lucy

Link to comment
Share on other sites

You can save an XML file the same way you could save any other file.One such way in PHP5 is the file_put_contents() function. To remove the spaces, you could do a text like manipulation of the XML file or (what I'd do), load() the file with the DOM class and then just save() it. This also eliminates the need for file_put_contents().As for update, it depends on quite a few factors. If the remote server sends a proper last modification time header, you could fetch that header with filemtime() and update the file if the filemtime() is greather then the filemtime() of your copy. If they are not sending that header, you'll either have to download the file on each request (eliminating the point of saving the file), or set a "cron job" ("Scheduled Task" in Windows) that will call the PHP file for fetching the XML file every now and then. That would however mean the file will not be always up to date.

Link to comment
Share on other sites

You can save an XML file the same way you could save any other file.One such way in PHP5 is the file_put_contents() function. To remove the spaces, you could do a text like manipulation of the XML file or (what I'd do), load() the file with the DOM class and then just save() it. This also eliminates the need for file_put_contents().As for update, it depends on quite a few factors. If the remote server sends a proper last modification time header, you could fetch that header with filemtime() and update the file if the filemtime() is greather then the filemtime() of your copy. If they are not sending that header, you'll either have to download the file on each request (eliminating the point of saving the file), or set a "cron job" ("Scheduled Task" in Windows) that will call the PHP file for fetching the XML file every now and then. That would however mean the file will not be always up to date.
boen_robotThanks that is very helpful, I'm not able to modify the php file though so I'm not sure if the filemtime() would work. Sorry to sound stupid though, but I didn't quite understand about the DOM class load(), would that be in the php or in the XML.I've included the generated XML as well if that helps.
<?xml version="1.0"?> <CasinoInfo>  <CasinoName> PhoneCasino </CasinoName>  <PartnerName> PhoneCasino </PartnerName>  <Generated> 2007-07-05 12:18:02 </Generated>  <Games>   <VideoPoker>	<title> Video Poker </title>	<about> A superb 5-Card Stud Poker game for novices and experts alike. Win 250 times your stake on a Royal Flush! Jacks or better pays out. Install NOW for free! </about>	<lastWinner> AL, Bristol just won 50 pence </lastWinner>   </VideoPoker>   <UnionJackpot>	<title> Union Jackpot </title>	<about> Britain's most patriotic fruit machine. Spin, nudge and hold your way on horizontal or diagonal lines to win. Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £2,413.79 </formatted>	  <penceInteger> 241379 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> JG, Dewsbury just won £1.00 </lastWinner>   </UnionJackpot>   <Roulette>	<title> Roulette </title>	<about> Probably the best Casino game in the world... Put a REAL Roulette game on your phone and place your chips on all your favourite combinations and patterns. Install NOW for free! </about>	<lastWinner> GS, Port Talbot just won 90 pence </lastWinner>   </Roulette>   <Blackjack>	<title> Blackjack </title>	<about> Beat the dealer to 21 and double your money! Bet as much or as little as you like, from 10p upwards. Install NOW for free! </about>	<lastWinner />   </Blackjack>   <Nudge7>	<title> Nudge7 </title>	<about> Nudge, hold and spin your way to our progressive jackpot which goes up with every spin! Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £645.19 </formatted>	  <penceInteger> 64519 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> AY, Corby just won 50 pence </lastWinner>   </Nudge7>   <MoneyBeach>	<title> Money Beach </title>	<about> Who thought you could ever make money by hitting the beach? You could win up to 50 times your stake! Install NOW for free! </about>	<lastWinner> DR, Doncaster just won 50 pence </lastWinner>   </MoneyBeach>   <LoveMachine>	<title> Love Machine </title>	<about> Oh won't you buy me a diamond ring? (Or failing that a Mercedes Benz). Put a positive spin on Valentine's Day with the Love Machine. </about>	<jackpot>	 <progressive>	  <formatted> £1,102.42 </formatted>	  <penceInteger> 110242 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> GT, DUNDEE just won £1.50 </lastWinner>   </LoveMachine>   <Hi-Lo>	<title> Hi-Lo </title>	<about> Higher! Lower! Rack up those winnings in our fast, fun and furious Hi Lo cards game! Install NOW for free! </about>	<lastWinner> JP, Exmouth just won £1.35 </lastWinner>   </Hi-Lo>   <Bingo!>	<title> Bingo! </title>	<about> Eyes down for genuine British Bingo hall style action on your mobile. Install NOW for free! </about>	<lastWinner> B in Cleethorpes just won £2.50 </lastWinner>   </Bingo!>  </Games> </CasinoInfo>

Link to comment
Share on other sites

I'm referring to PHP's DOM and DOM's load() function, as well as the save() function.What you need to do are not (necessarily) adjustments to the other company's PHP file, but your PHP file. If you don't have one, you'll need to create one. No way around it.As I said, if the last modification time is not set properly, you'll need to set up a cron job. Or, you could use an approach like the one(s) desribed in this topic.

Link to comment
Share on other sites

I'm referring to PHP's DOM and DOM's load() function, as well as the save() function.What you need to do are not (necessarily) adjustments to the other company's PHP file, but your PHP file. If you don't have one, you'll need to create one. No way around it.
Okay so just to clafiy I will need to create a php that loads the xml as a DOM and the saves it? Also will it save it onto the server automatically and is it possible to out put the saved file with with my own XML table/classes?Thanks for your help
Link to comment
Share on other sites

Okay so just to clafiy I will need to create a php that loads the xml as a DOM and the saves it? Also will it save it onto the server automatically and is it possible to out put the saved file with with my own XML table/classes?Thanks for your help
It's as automaic as the save() function goes. That is, once you call it, the file IS saved on whatever location you specify to that function. WHEN exactly do you call the function is your business.You can directly output the file as a string with the saveXML() function and do whatever string manipulations you have from then on. Or if those XML classes of yours rely on DOM, you might as well only load() the file, perform those actions and save() the file at the end. If they are SimpleXML based, you could use SimpleXML's simplexml_import_dom() function to load the DOM tree as a SimpleXML tree, do whatever you want and save it in the end.
Link to comment
Share on other sites

It's as automaic as the save() function goes. That is, once you call it, the file IS saved on whatever location you specify to that function. WHEN exactly do you call the function is your business.
The site (www.thephonecasino.com) has a live feed that constantly updates a jackpot total and a list of winners. It used to work okay, but was then transfered to another server and now doesn't work. I only started the job two months ago (having told them I've never used XML) and now I have this problem and I'm really worried I'll loose my job if I can't get it sorted.Sorry to keep on about this, but as I'm sure you can understand I'm really worried about it.ThanksLucy
Link to comment
Share on other sites

Are you programming in any particular language? Do you code in PHP?It is impossible to modify an XML file so that it automatically updates itself. It is just a text file and needs an outside programme to update it. This programme has been written in PHP by the previous developers and if you can't create your own or edit theirs then you are at a loss.If you need help writing the code, I would look to a PHP forum.Hope that is in anyway helpful.Dominic

The site (www.thephonecasino.com) has a live feed that constantly updates a jackpot total and a list of winners. It used to work okay, but was then transfered to another server and now doesn't work. I only started the job two months ago (having told them I've never used XML) and now I have this problem and I'm really worried I'll loose my job if I can't get it sorted.Sorry to keep on about this, but as I'm sure you can understand I'm really worried about it.ThanksLucy
Link to comment
Share on other sites

Are you programming in any particular language? Do you code in PHP?It is impossible to modify an XML file so that it automatically updates itself. It is just a text file and needs an outside programme to update it. This programme has been written in PHP by the previous developers and if you can't create your own or edit theirs then you are at a loss.If you need help writing the code, I would look to a PHP forum.Hope that is in anyway helpful.Dominic
Thanks for that, I know a VERY little bit of PHP, but will definately have a look at PHP forums.ThanksLucy
Link to comment
Share on other sites

Thanks for that, I know a VERY little bit of PHP, but will definately have a look at PHP forums.ThanksLucy
Cool, np. I don't code PHP but the things you will need to identify are: When the data changesHow to know that?How to get the dataHow to write the data to fileGood luck :)Dominic
Link to comment
Share on other sites

When the data changesHow to know that?How to get the dataHow to write the data to file
  1. Something like "constantly" as far as I get it. Meaning, when someone plays, the file immediatly changes. If they don't, the file remains as is.
  2. That's exactly his problem. He can't know that. That's why I reccomended a cron job or the method descibed in that other topic. True though, they require PHP knowledge, at least on a beginners' level.
  3. With the DOM load() function I gave a link to above. It's used in PHP. There are examples of it in the W3Schools' DOM tutorials.
  4. With the DOM save() function. Same as load() applies to it.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...