Wondering if someone can help me please. I've an xml file which has logs with date in this format - 2020-12-06T01:00:02.578+11:00.
I'd like to use xpath to search through the data and filter records between two dates. I'm not able to figure how I can do this via the xpath filter search itself.
Below is my code so far, the search filter does not work obvious reason as it is a text value. I need to covert this date first?
Below code of matching date using greater than symbol does not work.
**Sample XML:**
<data>
<faultRecord ack="no"
cause="config-error"
Action="deletePresent"
code="3564"
created="2020-12-06T01:00:02.578+11:00"/>
</data>
$xml = simplexml_load_file('faults.xml');
$faults = new SimpleXMLElement('faults.xml',null,true);
foreach($faults->xpath('//data/faultRecord[@created > "2020-12-06"]') as $faultRecord) {
foreach($faultRecord->attributes() as $Attribute => $value)
if ($Attribute == 'created' or $Attribute == 'description') {
echo "{$Attribute} = {$value} <br /> <br /> ";
}
}
Thank you
EDIT worked out a way to do this in case if it ever helps anyone:
$faults = new SimpleXMLElement('faults.xml',null,true);
foreach($faults->xpath('//data/faultRecord[@code = "3564"]') as $faultRecord) {
$date = strtotime($faultRecord->attributes()->created);
if ($date > 1607176802) {
foreach($faultRecord->attributes() as $Attribute => $value)
if ($Attribute == 'created' or $Attribute == 'description') {
echo "{$Attribute} = {$value} <br /> <br /> ";
}
}
}