Connecting Tech Pros Worldwide Forums | Help | Site Map

Read xml file

Member
 
Join Date: Feb 2008
Posts: 50
#1: Mar 10 '08
I've a ticker's code like this :
[html]
<?php
// load SimpleXML
$SECURITIES = new SimpleXMLElement('http://www.zet.com/xml/TableDt.xml', null, true);

echo <<<EOF
<marquee bgcolor="#333333" scrollamount="3" onmouseover=stop() onmouseout=start() ><font face='Time News Romance' font color='white' font size=4><table>


EOF;

foreach($SECURITIES as $STOCK) // loop
{
$change=$STOCK->Change;

echo "SYMBOL:{$STOCK->Symbol_code}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "PRICE:{$STOCK->Price}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

if($change==0)
{
echo "<img src='vang.gif'>$change</img>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
else
{
if($change>0)
{
echo "<img src='gre (2).gif'>$change</img>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
else
{
if($change<0)
{
echo "<img src='red.gif'>$change</img>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
}
}




}
echo '</table></marquee>';

?>[/html]

it's fine if my xml file is not updated.Now my xml file is updated every 30 seconds,so it get error like this:


Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: http://purpleasia.com/clients/xml/ba...leDt.xml:2309: parser error : expected '>' in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <Best2Bid>26</Best2 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: http://purpleasia.com/clients/xml/ba...leDt.xml:2309: parser error : Opening and ending tag mismatch: Best2Bid line 2309 and Best2 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <Best2Bid>26</Best2 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: http://purpleasia.com/clients/xml/ba...leDt.xml:2309: parser error : Premature end of data in tag STOCK line 2298 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <Best2Bid>26</Best2 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: http://purpleasia.com/clients/xml/ba...leDt.xml:2309: parser error : Premature end of data in tag SECURITIES line 1 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <Best2Bid>26</Best2 in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\VFMwebsite\VFM_test\ticker.php:4 Stack trace: #0 C:\wamp\www\VFMwebsite\VFM_test\ticker.php(4): SimpleXMLElement->__construct('http://purpleas...', 0, true) #1 {main} thrown in C:\wamp\www\VFMwebsite\VFM_test\ticker.php on line 4

Pls help me to solve this problem.Thank you so much

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Mar 11 '08

re: Read xml file


http://www.zet.com/xml/TableDt.xml does not exist, correct link?

If they update the XML it should not cause any problems for you. If the XML is being written, the web server will wait a period of time for the file to be come available (finished writing), then it gives you the XML.

is my understanding of your problem correct?
Member
 
Join Date: Feb 2008
Posts: 50
#3: Mar 12 '08

re: Read xml file


it have no problem from the link(link had given only for ex)
i get this xml file from the host and it will be updated from third party any morning from 7am-11am,this time my php page get error like that.(but it's ok when i refresh few times ,if refresh again ,again get error)
if dont have any solution for this can we hide the error page and appear a message :"loading page..." . can we do that?
thanks so much
Member
 
Join Date: Feb 2008
Posts: 50
#4: Mar 17 '08

re: Read xml file


any more solution for this proplem? need help urgently
Thanks so much
Reply