Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. entry_212_CA60CTF_2014-10-30_12-14-57.jpg
  2.  
  3. <?xml version="1.0"?>
  4. <Incidents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Count="3" Date="2014-10-30" Time="12:14:57" FileName="2014-10-30_dones_Hillsborough_Leisure_Centre.xml">
  5. <Incident>
  6. <EntryTime>2014-08-16T08:54:12</EntryTime>// want to group by this element
  7. <ExitTime>2014-08-16T17:03:51</ExitTime>
  8. </Incident>
  9.  
  10. if(file_exists($xmlFullFilename)) {
  11. $xmlDoc = new DomDocument();
  12. $xmlDoc->load($xmlFullFilename);
  13. $tmp = $xmlDoc->getElementsByTagName("Incidents");
  14. $root = $tmp->item(0);
  15. }
  16.  
  17. eg:<EntryTime>2014-08-16T08:46:17</EntryTime>...
  18.  
  19. $tmp = split(" ", $entryTime);
  20. $dateString = $tmp[0] . "T" . $tmp[1];
  21. $entryTimeNode = $xmlDoc->createElement("EntryTime", $dateString);
  22.  
  23. $dom = new DomDocument();
  24. $dom->loadXML( get_xml() );
  25.  
  26. $xp = new DOMXPath( $dom );
  27.  
  28. $d_list = array();
  29.  
  30. # get all EntryTime nodes in the document
  31. foreach ($xp->query("Incident/EntryTime") as $x) {
  32. # take a substring of the nodeValue corresponding to the date, put it in an array
  33. $d_list[ substr( $x->nodeValue, 0, 10 ) ] = 1;
  34. }
  35.  
  36. # $d_list now contains every date referenced in the file
  37. # if you only want the Incidents for a certain date, you obviously don't need to use
  38. # use a foreach loop!
  39. foreach ($d_list as $d => $v) {
  40. # select every EntryTime node where the value starts with $d
  41. # the /.. at the end returns its parent node, i.e. the Incident node
  42. foreach ($xp->query("Incident/EntryTime[starts-with(.,'$d')]/..") as $node) {
  43. # now do whatever you want with the Incident node data
  44. print_r($node);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement