I have an xml file that defines form fields. In the case of a list with optgroups, my xml would contain something 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 am trying to loop through nodes such as
foreach ($feed->fieldset[1]->field[$j]->children() as $c):
foreach($c->attributes() as $key => $value):
echo '<'.$c->getName().' '.$key.'="'.$value.'">'.$c.'</'.$c->getName().'><br>';
endforeach;
endforeach;
I know, probably doesn't make sense for the value to equal the label, but I'll worry about that later.
For now, I am trying to figure out how to loop through both the options and the options within an optgroup. Above loop is not showing the optgroup's options (as expected). Seems I probably have to do some recursion, but was wondering if there are better ways you might recommend, such as existing php xml functions that handle what I am trying to do (so far I have not found anything).
Thanks!
Aucun commentaire:
Enregistrer un commentaire