Here is my XML:
<?xml version="1.0" encoding="utf-8" ?>
<items>
<itemgroup name="ATM" column="1" sort="0">
<item formid="ATM 01" description="Option Teller Balance Sheet - ATM Dept. Ordering ONLY" unit="cello 500"/>
</itemgroup>
<itemgroup name="Data Processing" column="1">
<item formid="AACU 01" description="Receipt Voucher - 2 Part" unit="3600/box"/>
<item formid="AACU 04" description="Contract Collection Statement" unit="as Req."/>
<item formid="AACU 07" description="1-part Receipt Voucher - Cont. feed form" unit="5000/box"/>
<item formid="AACU 08" description="Share IRA Certificate" unit="2200/box"/>
<item formid="AACU 15" description="PTA PIN MAILER" unit="1800/box"/>
<item formid="AACU 15B" description="ONLINE ACCESS PIN MAILER" unit="2500/box"/>
</itemgroup>
</items>
I know I need to use code such as this:
$xml_file = "aacu-data.xml";
$xml = simplexml_load_file($xml_file);
but what I need to know is how I can retrieve attributes such as description and unit for say where formid="AACU 07" and be able to assign it to two variables such as $description and $unit.
WITH SOME MODIFICATIONS I got it to work:
$xml_file = "aacu-data.xml";
$xml = simplexml_load_file($xml_file);
foreach($xml->itemgroup as $itemgroup) {
foreach($itemgroup->children() as $items) {
echo $items->attributes()->formid . "<br>";
echo $items->attributes()->description . "<br>";
echo $items->attributes()->unit . "<br>";
}
}: