Changeset 15055 for greenstone3/trunk


Ignore:
Timestamp:
2008-03-06T14:11:14+13:00 (16 years ago)
Author:
xiao
Message:

add a method getNamedElements following the same concept of the method getNamedElement

File:
1 edited

Legend:

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

    r14641 r15055  
    694694    return null;
    695695  }
     696  /** returns a NodeList of elements: ancestor/node_name[@attribute_name='attribute_value']
     697   */
     698  public static NodeList getNamedElements(Element ancestor, String node_name, String attribute_name, String attribute_value) {
     699        MyNodeList node_list = new MyNodeList();
     700        NodeList children = ancestor.getElementsByTagName(node_name);
     701       
     702        if(children != null && children.getLength() > 0) {
     703           
     704            for (int i=0; i<children.getLength(); i++) {
     705                Node child = children.item(i);
     706                if (child.getNodeName().equals(node_name)) {
     707                    if (((Element)child).getAttribute(attribute_name).equals(attribute_value))
     708                        node_list.addNode(child);
     709                }           
     710            }           
     711        }
     712        return node_list;
     713  }
    696714 
    697715  public static int SORT_TYPE_STRING = 0;
Note: See TracChangeset for help on using the changeset viewer.