Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entry_212_CA60CTF_2014-10-30_12-14-57.jpg
- <?xml version="1.0"?>
- <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">
- <Incident>
- <EntryTime>2014-08-16T08:54:12</EntryTime>// want to group by this element
- <ExitTime>2014-08-16T17:03:51</ExitTime>
- </Incident>
- if(file_exists($xmlFullFilename)) {
- $xmlDoc = new DomDocument();
- $xmlDoc->load($xmlFullFilename);
- $tmp = $xmlDoc->getElementsByTagName("Incidents");
- $root = $tmp->item(0);
- }
- eg:<EntryTime>2014-08-16T08:46:17</EntryTime>...
- $tmp = split(" ", $entryTime);
- $dateString = $tmp[0] . "T" . $tmp[1];
- $entryTimeNode = $xmlDoc->createElement("EntryTime", $dateString);
- $dom = new DomDocument();
- $dom->loadXML( get_xml() );
- $xp = new DOMXPath( $dom );
- $d_list = array();
- # get all EntryTime nodes in the document
- foreach ($xp->query("Incident/EntryTime") as $x) {
- # take a substring of the nodeValue corresponding to the date, put it in an array
- $d_list[ substr( $x->nodeValue, 0, 10 ) ] = 1;
- }
- # $d_list now contains every date referenced in the file
- # if you only want the Incidents for a certain date, you obviously don't need to use
- # use a foreach loop!
- foreach ($d_list as $d => $v) {
- # select every EntryTime node where the value starts with $d
- # the /.. at the end returns its parent node, i.e. the Incident node
- foreach ($xp->query("Incident/EntryTime[starts-with(.,'$d')]/..") as $node) {
- # now do whatever you want with the Incident node data
- print_r($node);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement