Jump to content
unplugged_web

New to PHP please help

Recommended Posts

Do you mean now the local copy is not created? Huh, odd... if it wasn't, PHP was probably going to throw a warning at it too. What's the complete code now?
Since the XSLT has been enabled it has stopped creating a local copy although it did before the extension was swithed on. I tried removing
$xmlFile = 'http://stats.probability.tv/feed.php?key=mypassword

and then creating the remote.xml by using

<?phpif (!defined('FILE_APPEND'))  define('FILE_APPEND', 1);if (!function_exists('file_put_contents')){function file_put_contents($n, $d, $flag = false){  $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';  $f = @fopen($n, $mode);  if ($f === false)  {	return 0;  }  else  {	if (is_array($d)) $d = implode($d);	$bytes_written = fwrite($f, $d);	fclose($f);	return $bytes_written;  }}}$xml = "http://stats.probability.tv/feed.php?key=mypassword";$destination = dirname(__FILE__) . "/remote.xml"; //save the xml in a file called saved in the current folder$data = file_get_contents($xml);if (!$bytes = file_put_contents($destination, trim($data)))  echo "Writing to {$destination} failed";else  echo "Succesfully wrote {$destination}, saved {$bytes} bytes";?>

but as soon as I ran the xml_transform file it erased everything in remote.xml and saved a blank file.The entire code is:

<?php//Your files. The saved XSLT file, the remote XML, the location of the local copy and result.$xmlFile = 'http://stats.probability.tv/feed.php?key=mypassword'; //The remote file$xmlFileLocal = 'remote.xml'; //The location of the local copy of the remote file$xsltFile = 'structure.xsl'; //The XSLT file$newFile = 'Marquee.xml'; //The location of the transformed file//Display any PHP errors found further below (if any)ini_set('display_errors','On');//The definition of file_put_contents() in case it's not available which is most likely as that function was added in PHP5.0.0.if (!function_exists('file_put_contents')){if (!defined('FILE_APPEND')) {  define('FILE_APPEND', 1);}function file_put_contents($n, $d, $flag = false){  $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';  $f = @fopen($n, $mode);  if ($f === false)  {	return 0;  }  else  {	if (is_array($d)) $d = implode($d);	$bytes_written = fwrite($f, $d);	fclose($f);	return $bytes_written;  }}}//Save a local copy of the remote file at the specified location for a local copy//This will also stript out extra spaces at the beginning and the end of the documentfile_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));//Check if the XSLT extension is availableif (!function_exists('xslt_create')) {die('The XSLT extension is not enabled. Contact your host to enable it.');}//Prepare the XSLT processor.$xh = xslt_create();//Execute the transformationif (!xslt_process($xh, $xmlFileLocal, $xsltFile, $newFile)) {die('Error during transformation of "' . $xmlFile . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "' . $newFile . '"');}//Free the XSLT processor.xslt_free($xh);echo 'The script executed succesfully. A local copy of "' . $xmlFile . '" is available at "' . $xmlFileLocal . '" and a transformed by "' . $xsltFile . '" version is available at "' . $newFile . '".';?>

Share this post


Link to post
Share on other sites

Try to add

die('Local copy created');

right before

//Check if the XSLT extension is available

You should see the message in the die() and the transformation won't happen, but do you see the local copy (remote.xml) with proper contents in it?If not, try to replace

file_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));

with

file_put_contents(dirname(__FILE__) . '/' . $xmlFileLocal, trim(file_get_contents($xmlFile)));

If that doesn't help, I think we may have to resummon justsomeguy to solve that part.Once the local copy is saved properly, you can remove the die() and get back to the improper XSLT file location issue.

Share this post


Link to post
Share on other sites

I added that bit and it said that a local copy had been created, I checked it and it does have the right content.I seem to only be getting this problem when I try to transform it with the structure.xsl file.Thanks

Share this post


Link to post
Share on other sites
Try to add
die('Local copy created');

right before

//Check if the XSLT extension is available

You should see the message in the die() and the transformation won't happen, but do you see the local copy (remote.xml) with proper contents in it?If not, try to replace

file_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));

with

file_put_contents(dirname(__FILE__) . '/' . $xmlFileLocal, trim(file_get_contents($xmlFile)));

If that doesn't help, I think we may have to resummon justsomeguy to solve that part.Once the local copy is saved properly, you can remove the die() and get back to the improper XSLT file location issue.

I added that bit and it said that a local copy had been created, I checked it and it does have the right content.I seem to only be getting this problem when I try to transform it with the structure.xsl file.Thanks

Share this post


Link to post
Share on other sites

OK, I really didn't wanted to suggest that because it means worse performance, but it seems it may be the only way with your setup...reaplace

if (!xslt_process($xh, $xmlFileLocal, $xsltFile, $newFile)) {

with

if (!xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', $newFile, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile))) {

it's a really bad way of doing things, and I'm not even sure if it will work, but if it does, it's your only chance.Oh, and remove the

die('Local copy created');

of course.

Share this post


Link to post
Share on other sites
OK, I really didn't wanted to suggest that because it means worse performance, but it seems it may be the only way with your setup...reaplace
if (!xslt_process($xh, $xmlFileLocal, $xsltFile, $newFile)) {

with

if (!xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', $newFile, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile))) {

it's a really bad way of doing things, and I'm not even sure if it will work, but if it does, it's your only chance.Oh, and remove the

die('Local copy created');

of course.

I changed that bit, but all I got was a blank page. The remote.xml file hadn't changed either.

Share this post


Link to post
Share on other sites

Opps... syntax error. My fault. Add another ")" like so:

if (!xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', $newFile, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile)))) {

Share this post


Link to post
Share on other sites

Sorry to give you so many headaches, but I got another error:

Warning: Sablotron error on line 10: XML parser error 4: not well-formed (invalid token) in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 47Error during transformation of "http://stats.probability.tv/feed.php?key=mypassword" with "structure.xsl" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "Marquee.xml"

Line 10 is blank, but the code surrounding it is(lines 8-12):

//Display any PHP errors found further below (if any)ini_set('display_errors','On');//The definition of file_put_contents() in case it's not available which is most likely as that function was added in PHP5.0.0.if (!function_exists('file_put_contents'))

and line 47 is the

if (!xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', $newFile, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile)))) {

that I just added.

Share this post


Link to post
Share on other sites

Strange. Can you open the XML (remote.xml) and XSLT file in a browser? You should be seeing the XML tree. If you see an error instead, show me the EXACT contents of the XML file (probably remote.xml) in which you see an error AND the error message you see in the browser.

Share this post


Link to post
Share on other sites
Strange. Can you open the XML (remote.xml) and XSLT file in a browser? You should be seeing the XML tree. If you see an error instead, show me the EXACT contents of the XML file (probably remote.xml) in which you see an error AND the error message you see in the browser.
The remote.xml file does contain an error. The whole page reads:
This page contains the following errors:error on line 65 at column 704: error parsing attribute nameBelow is a rendering of the page up to the first error.Casino Casino 2007-07-30 22:17:30 Video Poker 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! JP, Exmouth just won ?1.00 Union Jackpot Britain's most patriotic fruit machine. Spin, nudge and hold your way on horizontal or diagonal lines to win. Install NOW for free! ?2,977.30 297730 SH, Winsford just won ?1.50 Roulette 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! CM, West Calder just won ?9.00 Blackjack 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! Nudge7 Nudge, hold and spin your way to our progressive jackpot which goes up with every spin! Install NOW for free! ?4,672.78 467278 SD, HALSTEAD just won 50 pence Money Beach Who thought you could ever make money by hitting the beach? You could win up to 50 times your stake! Install NOW for free! AF, Wymondham just won ?1.00 Love Machine 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. ?1,505.64 150564 LG, Huntly just won ?1.50 Hi-Lo Higher! Lower! Rack up those winnings in our fast, fun and furious Hi Lo cards game! Install NOW for free! HR, Edinburgh just won ?16.20

The error on line 65 that it is referring to is an exclaimation mark, but the copany that the live feed is coming from have said that it is valid XML.The source of the XML file is:

<?xml version="1.0"?> <CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-07-30 22:17:30 </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> JP, Exmouth just won ?1.00 </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,977.30 </formatted>	  <penceInteger> 297730 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> SH, Winsford just won ?1.50 </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> CM, West Calder just won ?9.00 </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> ?4,672.78 </formatted>	  <penceInteger> 467278 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> SD, HALSTEAD 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> AF, Wymondham just won ?1.00 </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,505.64 </formatted>	  <penceInteger> 150564 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> LG, Huntly 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> HR, Edinburgh just won ?16.20 </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> N in Stoke-On-Trent just won &#163;5.00 </lastWinner>   </Bingo!>  </Games> </CasinoInfo>

Share this post


Link to post
Share on other sites

Well, it's not. Ask them to try to open this file themselves in the browser and see if they can see the XML tree.BTW, you could also tell them that the file is not only "invalid" but is also "not well formed".Just... tell them to remove the "!" at the "bingo!" element. It's clear that's the only problem now. You could possibly remove it yourself, but you shouldn't be fixing their errors.

Share this post


Link to post
Share on other sites
Well, it's not. Ask them to try to open this file themselves in the browser and see if they can see the XML tree.BTW, you could also tell them that the file is not only "invalid" but is also "not well formed".Just... tell them to remove the "!" at the "bingo!" element. It's clear that's the only problem now. You could possibly remove it yourself, but you shouldn't be fixing their errors.
I asked them to remove it before and they said that they can't because "the feed format cannot be changed as it is being used by many other systems."When I initailly asked them to remove the ! they told me to look at http://www.w3.org/TR/2006/REC-xml11-20060816/#syntax stating that only & < and > are invalid characters.I'll ask them again to remove it, but don't know how much luck I'll have. I'm happy to remove the whole bingo element though if that makes any difference.

Share this post


Link to post
Share on other sites

It looks like boen is typing, but the company is full of crap. Point them back to the link they gave you. You can see that a start-tag is defined thusly:

STag	   ::=   	'<' Name (S Attribute)* S? '>'

Meaning it is composed of a Name followed by optional whitespace and one or more Attribute values. So this is what a Name is defined as:

Name	   ::=   	NameStartChar (NameChar)*

A NameStartChar, followed by NameChars. A NameChar and NameStartChar are defined like this:

NameStartChar	   ::=   	":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]NameChar	   ::=   	NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]

Nowhere in there does it say you can use the ! character, which is hex 21 (it would appear as #x21).So, according to that page, the ! character is not one of the allowed characters in a start tag.

Share this post


Link to post
Share on other sites
It looks like boen is typing, but the company is full of crap. Point them back to the link they gave you. You can see that a start-tag is defined thusly:
STag	   ::=   	'<' Name (S Attribute)* S? '>'

Meaning it is composed of a Name followed by optional whitespace and one or more Attribute values. So this is what a Name is defined as:

Name	   ::=   	NameStartChar (NameChar)*

A NameStartChar, followed by NameChars. A NameChar and NameStartChar are defined like this:

NameStartChar	   ::=   	":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]NameChar	   ::=   	NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]

Nowhere in there does it say you can use the ! character, which is hex 21 (it would appear as #x21).So, according to that page, the ! character is not one of the allowed characters in a start tag.

Thanks I'll tell them that. Hopefully they'll change it then

Share this post


Link to post
Share on other sites

Other systems are using it?!?! Don't make me laugh :) ! No one could possibly be using it when it's not well formed.Send them this as an argumentation:

http://www.w3.org/TR/REC-xml/#NT-STagShows what is valid start tag (and essentially, what's a valid name of an XML element). "!" is allowed in element contents and as you said, the only invalid characters in elements' contents are the special characters you mention (<,>,&). That however doesn't apply to XML character names, as there are more restrictions to them.http://www.w3.org/TR/REC-xml/#NT-NameShows what is valid XML name. According to the model, the first character must be a letter, "_" or ":" and can be followed by zero or more NameChar characters.http://www.w3.org/TR/REC-xml/#NT-NameCharShows what a valid NameChar is. It's a Letter, Digit, '.', '-', '_', ':', CombiningChar or Extender.The rest of the links at that point explain what is valid of those types. Now, exclanation mark is #x0021. Ceate an HTML file containing "& #x0021;" if you don't believe me. I don't see that character being valid in an XML name, and neither does any XML parser I'm trying to use.
Or just give a link to the whole topic.NOTE: remove the space between & and # in the quote above. I've only added it because this board interprets entities.[edit]It appears I was too slow :) [/edit]

Share this post


Link to post
Share on other sites
Other systems are using it?!?! Don't make me laugh :) ! No one could possibly be using it when it's not well formed.Send them this as an argumentation:Or just give a link to the whole topic.NOTE: remove the space between & and # in the quote above. I've only added it because this board interprets entities.[edit]It appears I was too slow :) [/edit]
Thats for that I'm going to e-mail them now and hopefully I'll hear from the first thing tomorrow. I'll let you know how I get on.

Share this post


Link to post
Share on other sites
Thats for that I'm going to e-mail them now and hopefully I'll hear from the first thing tomorrow. I'll let you know how I get on.
Sorry I'm back with more problems. The company has removed the ! mark and the remote.xml file is now fine and well formed, but I'm still getting:
Warning: Sablotron error on line 10: XML parser error 4: not well-formed (invalid token) in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 47Error during transformation of "http://stats.probability.tv/feed.php?key=mypassword" with "structure.xsl" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "Marquee.xml"
when I try to run the php file.The XML file that is now being output is:
<?xml version="1.0"?> <CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-08-01 12:32: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> JP, Exmouth just won ?3.00 </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> ?33.64 </formatted>	  <penceInteger> 3364 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> SH, Winsford just won ?1.50 </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> MI, Leicester just won ?1.00 </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> ?5,043.26 </formatted>	  <penceInteger> 504326 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> TJ, York 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> AF, Wymondham just won ?1.00 </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,567.64 </formatted>	  <penceInteger> 156764 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> LG, Huntly 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> ZB, CAMBRIDGE just won 60 pence </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> S in Wigan just won &#163;2.50 </lastWinner>   </Bingo>  </Games> </CasinoInfo>

Share this post


Link to post
Share on other sites

So what you're showing is THE contents of the local copy, right? Well, unless you've made changes to the XSLT file (potentially making it a not well formed XML document) it should all work. Can you open the XSLT file in a browser and see the tree just as with the XML file?If so, then... I'm really out of ideas. Contact your host, or better yet - migrate to one with PHP5 support. PHP5's XML parser is far more superior, so such errors shouldn't occur.If not, then show me the XSLT file after your changes so that I could locate the error.

Share this post


Link to post
Share on other sites
So what you're showing is THE contents of the local copy, right? Well, unless you've made changes to the XSLT file (potentially making it a not well formed XML document) it should all work. Can you open the XSLT file in a browser and see the tree just as with the XML file?If so, then... I'm really out of ideas. Contact your host, or better yet - migrate to one with PHP5 support. PHP5's XML parser is far more superior, so such errors shouldn't occur.If not, then show me the XSLT file after your changes so that I could locate the error.
I've looked at the live feed and the xml that the php is saving and it seems to be something to do with the £ symbols (I opened the xml file in Firefox and it had a ? where the £ was). They're there in the live feed, but when I open the xml file there not there and the line that is mentioned in the error is the first line that the £ symbols appear on. Could that be be the cause? I don't think I've changed the code for the XSL, but just incase the code is:
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:template match="/CasinoInfo">		<!--Parameter addded for performance's sake.		Otherwise double with "../CasinoName" within the for-each-->		<xsl:param name="casino" select="CasinoName"/>		<PhoneCasino>			<xsl:for-each select="Games/*">				<Casino>					<CasinoName>						<xsl:value-of select="$casino"/>					</CasinoName>					<Game>						<xsl:value-of select="title"/>					</Game>					<Winner>						<xsl:value-of select="lastWinner"/>					</Winner>					<won>						<xsl:value-of select="title"/>					</won>					<!--There seem to be some games that don't have a jackpot written.					If you want to have empty <Jackpot/> elements, remove this xsl:if element-->					<xsl:if test="jackpot">						<Jackpot>							<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/>						</Jackpot>					</xsl:if>				</Casino>			</xsl:for-each>		</PhoneCasino>	</xsl:template>	<!--Just to eliminate some of the extra spaces-->	<xsl:template match="text()">		<xsl:value-of select="normalize-space(.)"/>	</xsl:template></xsl:stylesheet>

This is what I can see when I open it and view the source in a browser.

Share this post


Link to post
Share on other sites

Hm. The £ theory sounds quite good. Well, here's an idea.First, in the PHP file, write

/*

right after

ini_set('display_errors','On');

and write

*/

right before

//Check if the XSLT extension is available

This will comment out everything in between, meaning PHP won't process it. That part was what fetches the remote and saves the local copy.OK. Now that this is out, open the local copy (remote.xml) and remove all occurances of the £ sign in it. Now try to execute the PHP file. If that sign is the problem, the transformation should be performed normally, and from then on, we'll try to think of a way to automatically remove it. At least this time it is Salbotron's fault, rather then the casino's fault, since you can see the XML tree in a browser.

Share this post


Link to post
Share on other sites
Hm. The £ theory sounds quite good. Well, here's an idea.First, in the PHP file, write
/*

right after

ini_set('display_errors','On');

and write

*/

right before

//Check if the XSLT extension is available

This will comment out everything in between, meaning PHP won't process it. That part was what fetches the remote and saves the local copy.OK. Now that this is out, open the local copy (remote.xml) and remove all occurances of the £ sign in it. Now try to execute the PHP file. If that sign is the problem, the transformation should be performed normally, and from then on, we'll try to think of a way to automatically remove it. At least this time it is Salbotron's fault, rather then the casino's fault, since you can see the XML tree in a browser.

I did that and this time it said that the error was on line 68:
<lastWinner> A in Sunderland just won 10.00 </lastWinner>

I thought it was worth removing the full stop, but that didn't help so I removed the whole line and it then said the error was on the previous <lastWinner> tag. I copied and pasted in everything from the Marquee.xml file and it still returned an error. It seems to be always returning an error for the last tag with content in it before the closing tags at the end. I don't know if that makes sense for not, but it seems that is the pattern, no matter what I do.

Share this post


Link to post
Share on other sites

I thought I'd try copying lastWinner from the remote xml file and pasting it into the xsl just incase there was any character differences. Then removed the <xsl:if test="jackpot"> from xsl file. This seemed to work better, the error had moved up tp line 26. The error said

Sablotron error on line 26: XML parser error 7: mismatched tag
I've checked the tags (and double checked them), but there doesn't appear to be any mismatched tags. I don't know if it helps, but I thought it would be an idea if I included the code for the xml and the xsl files.The xml code is
<?xml version="1.0"?> <CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-08-02 12:36:48 </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> GH, London 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> 93.49 </formatted>	  <penceInteger> 9349 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> SH, Winsford just won 1.50 </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> JP, Exmouth just won 9.00 </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> 5,259.15 </formatted>	  <penceInteger> 525915 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> CG, London just won 3.00 </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> CM, Kirkcaldy 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,576.65 </formatted>	  <penceInteger> 157665 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> LG, Huntly 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> AM, GRANTOWN-ON-SPEY just won 54 pence </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> A in Sunderland just won 10.00 </lastWinner>   </Bingo>  </Games> </CasinoInfo>

While the xsl code is

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:template match="/CasinoInfo">		<!--Parameter addded for performance's sake.		Otherwise double with "../CasinoName" within the for-each-->		<xsl:param name="casino" select="CasinoName"/>		<PhoneCasino>			<xsl:for-each select="Games/*">				<Casino>					<CasinoName>						<xsl:value-of select="$casino"/>					</CasinoName>					<Game>						<xsl:value-of select="title"/>					</Game>					<Winner>						<xsl:value-of select="lastWinner"/>					</Winner>					<won>						<xsl:value-of select="title"/>					</won>						<Jackpot>							<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/>						</Jackpot>					</xsl:if>				</Casino>			</xsl:for-each>		</PhoneCasino>	</xsl:template>	<!--Just to eliminate some of the extra spaces-->	<xsl:template match="text()">		<xsl:value-of select="normalize-space(.)"/>	</xsl:template></xsl:stylesheet>

After doing that I tried removing the /* */, but there was still an error. It just said that

Sablotron error on line 10: XML parser error 4: not well-formed (invalid token) in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 47
It now seems to return the same line 10 error whether those elements are there or not

Share this post


Link to post
Share on other sites

I thought I'd try deleting the originally files from the server, chaning the name of the output file and then re-uploading them. This time I got a result saying:

Warning: Sablotron error on line 68: cannot open file 'c:/windows/system32/inetsrv/Result.xml' in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 47Error during transformation of "remote.xml" with "structure.xsl" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "Result.xml"
Before I opened the php file I created a blank xml file and called it Result.xml file so I don't know why it's saying there's an error on line 68.I've just had one thought, could it be that ,for whatever reason, the host is preventing the file being written?

Share this post


Link to post
Share on other sites

I see a mismatch in the XSLT file. The line:

</xsl:if>

should be gone as well. But as I told you when I gave you the XSLT, in that case, you'll have empty <jackpot/> elements in your output whenever the game doesn't have a jackpot to begin with.The XML file is fine, or so it seems.Maybe disability to write "Result.xml" is the error. OK. Let's try this:Replace

if (!xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', $newFile, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile)))) {die('Error during transformation of "' . $xmlFile . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "' . $newFile . '"');}

with

if (!$transformation = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', null, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile)))) {die('Error during transformation of "' . $xmlFileLocal . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct.');}if (!file_put_contents($newFile, $transformation)) {die('Unable to write "' . $newFile . '". Make sure the definition of file_put_contents() is available');}

And move (that is, remove it from that spot, and place) the "/*" before this

//Save a local copy of the remote file at the specified location for a local copy//This will also stript out extra spaces at the beginning and the end of the documentfile_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));

You need that in order to enable the file_put_contents() function (which will write the output to a file) but still disable the fetching from the remote site. That way, you'll rely on the full proof file_put_contents() function, rather then the unstable Salbotron.

Share this post


Link to post
Share on other sites

Okay something diferent happened this time. I got an error message that said:

Fatal error: Call to undefined function: file_put_contents() in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 37
I tried to get the hosting company to upgrading to PHP 5, but they only said that they only support that on their Unix platforms. The site I'm working on was built in ASP and unfortunately the Windows platform hasn't moved to PHP 5 yet.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...