Fix for QueryPath for removing an XML item

  1. function mymodule_add_language_xml($form, &$form_state) {
  2.     /*
  3.     ...
  4.     */
  5.     $qp = qp($file);
  6.     if ($form_state['values']['op'] == 'Delete') {
  7.       $qp->find('languageList')->find('item');
  8.       foreach ($qp as $i => $item) {
  9.         if ($item->attr('id') == $language) {
  10.           // need to remove just the item with the id equal to $language
  11.           // but this call removes all items inside languageList. Sad panda :-(
  12.           $item->remove();
  13.         }
  14.       }
  15.     }
  16.     /*
  17.     ...
  18.     */
  19. }
  20.  
  21.  
  22. // the relevant portion of the xml file...
  23.         <languageList default="en-US">
  24.  
  25.                 <item id="en-US" title="language_en-US"/>
  26.                 <item id="es" title="language_es"/>
  27.  
  28.         </languageList>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.