Changeset 15055

Show
Ignore:
Timestamp:
06.03.2008 14:11:14 (11 years ago)
Author:
xiao
Message:

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

Files:
1 modified

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;