I have an xml file that looks like this
<?xml version="1.0" encoding="UTF-8" ?>
<dates>
<date>
<Item Name="History" Type="List">
<Item Name="received" Type="Date">2015/12/18 00:00</Item>
<Item Name="accepted" Type="Date">2016/03/31 00:00</Item>
<Item Name="aheadofprint" Type="Date">2016/04/14 00:00</Item>
<Item Name="entrez" Type="Date">2016/04/15 06:00</Item>
<Item Name="pubmed" Type="Date">2016/04/15 06:00</Item>
<Item Name="medline" Type="Date">2016/04/15 06:00</Item>
</Item>
</date>
<date>
<Item Name="History" Type="List">
<Item Name="epublish" Type="Date">2016/05/23 00:00</Item>
<Item Name="entrez" Type="Date">2016/07/12 06:00</Item>
<Item Name="pubmed" Type="Date">2016/07/12 06:00</Item>
<Item Name="medline" Type="Date">2016/07/12 06:00</Item>
<Item Name="pmc-release" Type="Date">2017/01/01 00:00</Item>
</Item>
</date>
</dates>
I am trying to get values of both the "name" attribute and the "date" attribute. I have used the code below
<?php
$xml = simplexml_load_file('dates.xml');
foreach( $xml->date->Item->children() as $v){
$k = 'date';
echo $k ."=". $v . "<br>";
}
?>
This code returns the following results
date=2015/12/18 00:00
date=2016/03/31 00:00
date=2016/04/14 00:00
date=2016/04/15 06:00
date=2016/04/15 06:00
date=2016/04/15 06:00
I am a bit confused why the snippet above does not loop through the two nodes. I am also looking for suggestions on how to also "echo out" the name attribute so as to have output that looks like this:
received date=2015/12/18 00:00
accepted date=2016/03/31 00:00
aheadofprint date=2016/04/14 00:00
entrez date=2016/04/15 06:00
pubmed date=2016/04/15 06:00
pubmed date=2016/04/15 06:00
Thanks in advance