Richard Luckhurst wrote: > Hi Jochem, > > Thanks for your reply > >>> <?xml version="1.0" encoding="UTF-8"?> >>> <?ypsilon RNGSchema="fareResponse.rnc" type="compact"?> > > JM> I'm fairly certain that this 'ypsilon' tag is going to cause a > JM> problem - although that's just a guess, it's based on the 'knowledge' > JM> that a valid XML document *must* have only 1 root element > JM> (which would be 'fareResponse' in this case). > > That makes sense when I think about it. > > > JM> do as Roman says and post the simpleXML code you have so far. > > I have done very little with Simple XML as I can't even get anything back out of > it. I have found the examples very confusing and I am obviously missing the > point of SimpleXML as it is obvious others are getting it to work. > > $file = "test.xml"; > > $data = simplexml_load_file($file); > var_dump($data); > > Produces the following > > object(SimpleXMLElement)#1 (5) { > ["@attributes"]=> > array(2) { > ["cntTarifs"]=> > string(3) "122" > ["offset"]=> > string(1) "0" > } > ["fares"]=> > object(SimpleXMLElement)#2 (1) { > ["fare"]=> > array(2) { > [0]=> > object(SimpleXMLElement)#6 (2) { > ["@attributes"]=> > array(11) { > ["fareId"]=> > string(8) "11429927" > ["fareType"]=> > string(3) "PUB" > ["checked"]=> > string(5) "false" > ["class"]=> > string(1) "V" > ["depApt"]=> > string(3) "SYD" > ["dstApt"]=> > string(3) "LON" > ["paxType"]=> > string(3) "ADT" > ["vcr"]=> > string(2) "OS" > ["cos"]=> > string(1) "E" > ["yyFare"]=> > string(5) "false" > ["avail"]=> > string(5) "false" > } > ["fareBases"]=> > object(SimpleXMLElement)#8 (1) { > ["fareBase"]=> > array(3) { > [0]=> > string(5) "VLOX2" > [1]=> > string(5) "VLOX2" > [2]=> > string(5) "VLOX2" > } > } > } > [1]=> > object(SimpleXMLElement)#7 (2) { > ["@attributes"]=> > array(11) { > ["fareId"]=> > string(8) "11429924" > ["fareType"]=> > string(3) "PUB" > ["checked"]=> > string(5) "false" > ["class"]=> > string(1) "M" > ["depApt"]=> > string(3) "SYD" > ["dstApt"]=> > string(3) "LON" > ["paxType"]=> > string(3) "ADT" > ["vcr"]=> > string(2) "OS" > ["cos"]=> > string(1) "E" > ["yyFare"]=> > string(5) "false" > ["avail"]=> > string(5) "false" > } > ["fareBases"]=> > object(SimpleXMLElement)#9 (1) { > ["fareBase"]=> > array(3) { > [0]=> > string(5) "MLOW2" > [1]=> > string(5) "MLOW2" > [2]=> > string(5) "MLOW2" > } > } > } > } > } > ["tarifs"]=> > object(SimpleXMLElement)#3 (2) { > ["@attributes"]=> > array(1) { > ["currency"]=> > string(3) "USD" > } > ["tarif"]=> > array(2) { > [0]=> > object(SimpleXMLElement)#10 (2) { > ["@attributes"]=> > array(9) { > ["tarifId"]=> > string(8) "11429927" > ["adtBuy"]=> > string(6) "675.07" > ["adtSell"]=> > string(6) "675.07" > ["chdBuy"]=> > string(6) "675.07" > ["chdSell"]=> > string(6) "675.07" > ["infBuy"]=> > string(6) "675.07" > ["infSell"]=> > string(6) "675.07" > ["topCar"]=> > string(5) "false" > ["topHotel"]=> > string(5) "false" > } > ["fareXRefs"]=> > object(SimpleXMLElement)#12 (1) { > ["fareXRef"]=> > string(8) "11429927" > } > } > [1]=> > object(SimpleXMLElement)#11 (2) { > ["@attributes"]=> > array(9) { > ["tarifId"]=> > string(8) "11429926" > ["adtBuy"]=> > string(6) "714.83" > ["adtSell"]=> > string(6) "714.83" > ["chdBuy"]=> > string(6) "714.83" > ["chdSell"]=> > string(6) "714.83" > ["infBuy"]=> > string(6) "714.83" > ["infSell"]=> > string(6) "714.83" > ["topCar"]=> > string(5) "false" > ["topHotel"]=> > string(5) "false" > } > ["fareXRefs"]=> > object(SimpleXMLElement)#13 (1) { > ["fareXRef"]=> > string(8) "11429926" > } > } > } > } > ["taxes"]=> > object(SimpleXMLElement)#4 (2) { > ["@attributes"]=> > array(1) { > ["currency"]=> > string(3) "USD" > } > ["tax"]=> > string(6) "201.52" > } > ["vcrSummary"]=> > object(SimpleXMLElement)#5 (1) { > ["vcr"]=> > array(2) { > [0]=> > string(2) "AA" > [1]=> > string(2) "PR" > } > } > } > > > So I can clearly see the data I want is there. However I have tried the > following > > foreach ($data->fares as $fares) > { > print "{$fares->fares} \n"; this print line is crufty. don't bother to print $fares->fare until you know what $fares is. in fact take a another step back: var_dump($data->fares); > } > maybe this? : foreach ($data->fares->fare as $fare) { var_dump($fare); } > And that just produces a blank line. It is obvious to me that > I am not on the right track. I would disagree - given the initial output your on exactly the right track, maybe you should not get discouraged so easily because the track is somewhat wider and/or longer than you had hoped. it takes time and a bit of dedication before you get to a stage where writing certain code (e.g. using simpleXML) becomes second nature and you know what you are doing so well that you manage to get it right first. below you'll find a snippet of a post made by Rasmus Lerdorf on the subject of simple XML to php lists (if that name rings no bells, go find out who he his before replying ;-): ---------------------------------- <?php $rss = simplexml_load_file('http://jtjohnston.ca/jtjohnston.rss'); $channel = $rss->channel; echo <<<EOB <img src="{$channel->image->url}" style="float: right;"/> <h1>{$channel->title}</h1> <h2>{$channel->description}</h2> EOB; foreach($channel->item as $item) { echo <<<EOB <h3><a href="{$item->link}">{$item->title}</a> ({$item->pubDate})</h3> {$item->description} <br clear="left" /> <hr /> EOB; } ?> and here are some links ------------------------------------- http://www.sematopia.com/?p=142 http://yahoo.progphp.com/flickr_api.phps http://php.net/simplexml (read the user notes also) and lastly here is Rasmus correcting my mistaken assumption about the state of simpleXML (especially in regard to var_dump() - this should indicate to you that you'll save yourself alot of headache if your running 5.1.x): http://marc.theaimsgroup.com/?l=php-dev&m=116370498918783&w=2 > Regards > > Richard Luckhurst > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php