Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void setIdentityAttribute(Document document, String attributeValue) { boolean isFound = false; NodeList propertyList = document.getElementsByTagName("Property"); for (int i = 0; i < propertyList.getLength(); i++) { Node node = propertyList.item(i); for (int j = 0; j < node.getAttributes().getLength(); j++) { Node attribute = node.getAttributes().item(j); if (attribute.getNodeName().equals("name") && attribute.getNodeValue().equals(attributeValue)) { Element element = (Element) node; element.setAttribute("isIdentity", "true"); isFound = true; break; } } if (isFound) break; } } }