How can i get the value of attribute in of a xml node in php?

HentaiAnimeMan

New Member
I'm using simplexml to read a xml file. So far i'm unable to get the attribute value i'm looking for. this is my code.\[code\] if(file_exists($xmlfile)){ $doc = new DOMDocument(); $doc->load($xmlfile); $usergroup = $doc->getElementsByTagName( "preset" ); foreach($usergroup as $group){ $pname = $group->getElementsByTagName( "name" ); $att = 'code'; $name = $pname->attributes()->$att; //not working $name = $pname->getAttribute('code'); //not working if($name==$preset_name){ echo($name); $group->parentNode->removeChild($group); } } }\[/code\]and my xml file looks like\[code\]<presets><preset> <name code="default">Default</name> <createdBy>named</createdBy> <icons>somethignhere</icons> </preset></presets>\[/code\]
 
Back
Top