xml - How can I add attributes to already made elements using PHP? -


i have xml sheet made , i've spent hours looking online way add attributes elements. great! if need more info parts of xml let me know i'll happy provide ever needed!

use simplexml job , dom outputting nicely:

$xmlstr = <<<xml <root>     <fruit origin="brazil">banana</fruit>     <fruit origin="germany">apple</fruit>     <fruit origin="spain">tomato</fruit> </root> xml;  $xml = simplexml_load_string($xmlstr);  $xml->fruit[0]->addattribute("state","fresh"); // add state="fresh" banana 

see post on how generate structured output passing $xml dom: php simplexml how save file in formatted way?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -