hi, i'm trying to display this XML rss i receive using PHP , and its not working for me. can anyone help displaying this? this is the XML code: <RESPONSE> <EXPR>CAD</EXPR> <EXCH>USD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Thu, 10 May 2001 21:00:00 GMT</DATE> <ASK>1.5432</ASK> <BID>1.542</BID> </CONVERSION> <EXPR>CAD</EXPR> <EXCH>CAD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Fri, 11 May 2001 14:29:54 GMT</DATE> <ASK>1.0000</ASK> <BID>1.000</BID> </CONVERSION> </RESPONSE> Code (markup): this is the code i wrote, the problem is that the EXPR EXCH... are at the sample level so running a foreach loop is a problem. <?php oandaObj = simplexml_load_file("XMLFILENNAME.xml"); $oandaArr = $oandaObj; ?> <ul> <?php foreach ($oandaArr as $key): ?> <li><?php echo $oandaArr->EXPR;?></li> <li><?php echo $oandaArr->EXCH;?></li> <li><?php echo $oandaArr->AMOUNT;?></li> <li><?php echo $oandaArr->NPRICES;?></li> <li><?php echo $oandaArr->CONVERSION->DATE;?></li> <li><?php echo $oandaArr->CONVERSION->BID;?></li> <li><?php echo $oandaArr->CONVERSION->ASK;?></li> <?php endforeach;?> </ul> Code (markup):
This isn't a valid xml format, or at least not one that is logically formed. There's nothing to associate the <EXPR /> <EXCH /> <AMOUNT /> <NPRICES /> with anything. Where did this feed come from.
Check this out, will probably make your life real easy. http://php.net/manual/en/function.xml-parse-into-struct.php
Given xml is not logically formed... There's nothing to associate the <EXPR /> <EXCH /> <AMOUNT /> <NPRICES /> with anything. it should be in following format : <RESPONSE> <RESPONSE> <EXPR>CAD</EXPR> <EXCH>USD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Thu, 10 May 2001 21:00:00 GMT</DATE> <ASK>1.5432</ASK> <BID>1.542</BID> </CONVERSION> <EXPR>CAD</EXPR> <EXCH>CAD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Fri, 11 May 2001 14:29:54 GMT</DATE> <ASK>1.0000</ASK> <BID>1.000</BID> </CONVERSION> </RESPONSE>
Given xml is not logically formed... There's nothing to associate the <EXPR /> <EXCH /> <AMOUNT /> <NPRICES /> <CONVERSION> with anything. it should be in following format : <RESPONSES> <RESPONSE> <EXPR>CAD</EXPR> <EXCH>USD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Thu, 10 May 2001 21:00:00 GMT</DATE> <ASK>1.5432</ASK> <BID>1.542</BID> </CONVERSION> </RESPONSE> <RESONSE> <EXPR>CAD</EXPR> <EXCH>CAD</EXCH> <AMOUNT>1</AMOUNT> <NPRICES>1</NPRICES> <CONVERSION> <DATE>Fri, 11 May 2001 14:29:54 GMT</DATE> <ASK>1.0000</ASK> <BID>1.000</BID> </CONVERSION> </RESPONSE> </RESPONSES> Sheetal
@Sheetal - thanks, and you're right, its not a proper XML format, that's my problem with running a loop around it, some params don't respond well. I think this XML , the params should be accessed manually...