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
Post a Comment