i have xml file defines form fields. in case of list optgroups, xml contain like
<field name="expertise" type="multilist" label="area of expertise" > <option value="disaster management">disaster management </option> <option value="energy security">energy security </option> <optgroup label="environment"> <option value="climate">climate </option> <option value="resource security">resource security </option> </optgroup> </field>
i trying loop through nodes such as
foreach ($feed->fieldset[1]->field[$j]->children() $c): foreach($c->attributes() $key => $value): echo '<'.$c->getname().' '.$key.'="'.$value.'">'.$c.'</'.$c->getname().'><br>'; endforeach; endforeach;
i know, doesn't make sense value equal label, i'll worry later.
for now, trying figure out how loop through both options , options within optgroup. above loop not showing optgroup's options (as expected). seems have recursion, wondering if there better ways might recommend, such existing php xml functions handle trying (so far have not found anything).
thanks!
use xml parser
<?php $myxmldata = '<field name="expertise" type="multilist" label="area of expertise"> <option value="disaster management">disaster management </option> <option value="energy security">energy security </option> <optgroup label="environment"> <option value="climate">climate </option> <option value="resource security">resource security </option> </optgroup> </field>'; $xml=simplexml_load_string($myxmldata); print_r($xml);
Comments
Post a Comment