Page 1 of 1

accessing xml attributes

Posted: Thu Oct 07, 2010 3:42 am
by pavanaradhya
Hi,

I have a xml file with the following format.

Code: Select all

<?xml version="1.0"?>
<schools>
   <school>
      <id>100</id>
      <type>Govt</type>
      <details coed="1">
         <name>ABC High School</name>
         <address># 5, Bangalore</address>
         <girls>120</girls>
         <boys>100</boys>
         <staff>25</staff>
      </details>
   </mk>
   <mk>
      <id>200</id>
      <type>Pvt</type>
      <details coed="0">
         <name>XYZ school</name>
         <address>No 121, Bangalore</address>
         <girls>450</girls>
         <boys>0</boys>
         <staff>30</staff>>
      </details>
   </school>
</schools>

the file name is school.xml

I am trying to access the elements and attributes of xml elements.

My code goes something like this

------------------------------------------------------------------

Code: Select all

$file=school.xml;

$xmlfile = $xmlparse->GetXMLTree($file);

foreach ($xmlfile[schools][0][school] as $schl){

	foreach ($schl[DETAILS] as $detail){

		$detail[NAME][0][VALUE]  ---accessing <name>
		$detail[ADDRESS][0][VALUE]  ---accessing <address>
	}	
}
------------------------------------------------------------------------------

I want to know how can I access attribute "coed" of details node? Can anyone help me? Its very urgent.

Regards,
Pavan

Re: accessing xml attributes

Posted: Thu Oct 07, 2010 4:21 am
by requinix
Where did $xmlparse come from? And in case your answer isn't what I'm looking for, what does

Code: Select all

echo get_class($xmlparse);
output?