bateman Posted January 3, 2014 Share Posted January 3, 2014 So I've tried 6 different methods of pulling the data from the xml but each time I get nothing. I KNOW it's going to be something stupidly simple, but at the moment I'm stumpped. Here is the code I'm working with, and not that it's not complete as I still need to write in the glob code to limit the results to a single date. Edit: the print is commented because I used it to show me that the xml is reading. $date = date("Y-m-d"); //echo $fdate; $glob = "./fromdb/TimesheetBackup_" . $date. "*.xml"; foreach (glob ($glob) as $result) { echo $result; $xml = simplexml_load_file($result); $count = 0; //print_r($xml);// "<br> $xml"; foreach ($xml->tasks[] as $tasks): $starttimeb = $tasks['startDate']; $starttime = substr($starttimeb, -8, -1); $endtime = $tasks->key->endDate; echo $starttime; echo "<br> $endtime"; endforeach; } and a sample of the xml (end of a 48 record xml) <task> <taskId>f620bba390874d9fa41ddc4384ac0ba0</taskId> <projectId>7ab307cc59e84219b5e1b7b6215a7400</projectId> <description></description> <location>552 Pandora Ave, Victoria, BC V8W 1N7</location> <startDate>2014-01-02T13:15:00</startDate> <endDate>2014-01-02T16:33:00</endDate> <deleted>false</deleted> <endTime>0</endTime> <startTime>0</startTime> <lastUpdate>1388709184182</lastUpdate> <paid>0</paid> <feeling>0</feeling> </task> </tasks> </timesheet> I'm trying to get this to work with a xml that's created by the android app Timesheet. This is from it's auto backup system so I have no control over the output of the xml. Link to comment https://forums.phpfreaks.com/topic/285066-xml-not-opening-data/ Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 yes, but you haven't told us what the debugging echo/print_r statements showed. for all we know the glob() isn't finding any files because the path, filename, letter-case, or date format isn't correct. Link to comment https://forums.phpfreaks.com/topic/285066-xml-not-opening-data/#findComment-1463725 Share on other sites More sharing options...
Barand Posted January 3, 2014 Share Posted January 3, 2014 try it like this foreach ($xml->tasks->task as $task) { echo $task->startDate . '<br>'; } Link to comment https://forums.phpfreaks.com/topic/285066-xml-not-opening-data/#findComment-1463731 Share on other sites More sharing options...
bateman Posted January 3, 2014 Author Share Posted January 3, 2014 the glob was showing the file names, and the foreach you posted worked, now I just need to format it for my needs (the substr and such, which I've already tested). Right now I have it outputing to the screen, but once it's done, it's going to be a cron update page. Thank you Link to comment https://forums.phpfreaks.com/topic/285066-xml-not-opening-data/#findComment-1463737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.