Changeset 31868

Show
Ignore:
Timestamp:
10.08.2017 14:20:15 (2 years ago)
Author:
kjdon
Message:

added new method replaceNamedItemInList

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r31166 r31868  
    868868    } 
    869869 
     870  /* Have an element with a set of children, attributes name="x". Replace the specified item in the list with new_item. */ 
     871  /* this assumes we only have children of the same node name. if going tro have mixed lists, need to test on node name as well */ 
     872  public static void replaceNamedItemInList(Element item_list, String item_node_name, String name_att, String item_name, Element new_item) { 
     873    Node child = item_list.getFirstChild(); 
     874    while(child != null) { 
     875      if (child.getNodeName().equals(item_node_name) && ((Element)child).getAttribute(name_att).equals(item_name)) { 
     876    //replace the element 
     877    item_list.insertBefore(item_list.getOwnerDocument().importNode(new_item, true), child); 
     878    item_list.removeChild(child); 
     879    return; 
     880      } 
     881      child = child.getNextSibling(); 
     882    } 
     883 
     884  } 
    870885    /** 
    871886     * Given a Node representing an Element or Document, will return the