accessing xml attributes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pavanaradhya
Forum Newbie
Posts: 1
Joined: Thu Oct 07, 2010 3:38 am

accessing xml attributes

Post 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
Last edited by Benjamin on Thu Oct 07, 2010 8:06 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: accessing xml attributes

Post 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?
Post Reply