- Timestamp:
- 2012-07-10T16:28:41+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r25925 r25926 935 935 // not found 936 936 return null; 937 937 } 938 939 public static NodeList getNamedElementsNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value) 940 { 941 MyNodeList result = new MyNodeList(); 942 NodeList children = parent.getChildNodes(); 943 for (int i = 0; i < children.getLength(); i++) 944 { 945 Node child = children.item(i); 946 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace_uri) && child.getLocalName().equals(node_local_name)) 947 { 948 if (((Element) child).getAttribute(attribute_name).equals(attribute_value)) 949 result.addNode(child); 950 } 951 } 952 return result; 953 } 954 955 public static NodeList getElementsWithAttributesNS(Element parent, String namespace_uri, String node_local_name, String[] attribute_names, String[] attribute_values) 956 { 957 if (attribute_names.length == 0 || attribute_names.length != attribute_values.length) 958 { 959 return new MyNodeList(); 960 } 961 962 MyNodeList result = new MyNodeList(); 963 964 NodeList matchingNodes = GSXML.getNamedElementsNS(parent, namespace_uri, node_local_name, attribute_names[0], attribute_values[0]); 965 for (int i = 0; i < matchingNodes.getLength(); i++) 966 { 967 Element current = (Element) matchingNodes.item(i); 968 boolean nodeMatches = true; 969 for (int j = 1; j < attribute_names.length; j++) 970 { 971 String currentName = attribute_names[j]; 972 String currentValue = attribute_values[j]; 973 if (!current.getAttribute(currentName).equals(currentValue)) 974 { 975 nodeMatches = false; 976 break; 977 } 978 } 979 980 if (nodeMatches) 981 { 982 result.addNode(current); 983 } 984 } 985 986 return result; 987 } 988 989 public static void removeElementsWithAttributesNS(Element parent, String namespace_uri, String node_local_name, String[] attribute_names, String[] attribute_values) 990 { 991 NodeList matchingNodes = GSXML.getElementsWithAttributesNS(parent, namespace_uri, node_local_name, attribute_names, attribute_values); 992 for (int i = 0; i < matchingNodes.getLength(); i++) 993 { 994 parent.removeChild(matchingNodes.item(i)); 995 } 938 996 } 939 997 … … 955 1013 parent.removeChild(old_elem); 956 1014 } 957 958 1015 } 959 1016
Note:
See TracChangeset
for help on using the changeset viewer.