php - Update XML node attribute -
i'm trying following without success. can me out why attribute imageid not changed?
$dom = new domdocument; $dom->loadxml($appcom_file_name); $frames = $dom->getelementsbytagname('frame'); foreach ($frames $frame) { if ($frame->getattribute('imageid') == '') { $frame->setattribute('imageid', $id); } } $dom->savexml();
xml source:
<template> <appcom> <page> <defaultvalues> <frame id="frame_01_0" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> <frame id="frame_02_0" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> <frame id="frame_03_0" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> </defaultvalues> </page> <page> <defaultvalues> <frame id="frame_01_1" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> <frame id="frame_02_1" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> <frame id="frame_03_1" deltarotation="0" deltascale="100" deltax="0" deltay="0" imageid="" /> </defaultvalues> </page> </appcom> </template>
i tested code , obviously, i'm getting error $id
not defined. have tried changing line:
$frame->setattribute('imageid', $id);
to this:
$frame->setattribute('imageid', $frame->getattribute('id'));
?
and of course, print results screen use echo
:
echo $dom->savexml();
Comments
Post a Comment