Given a xml file as input howto modify a attribute of a tag with a new string value?
Function is
updateXMLAttribute(Document doc , String tag, String at
I assume, by Document you mean org.w3c.dom.Document:
updateXMLAttribute(Document doc , String tag, String attribute, String newValue) {
NodeList nodes = doc.getElementsByTagName(tag);
for(int i=0; i<nodes.getLength(); i++) {
if(nodes.item(i) instanceof Element) {
Element elem = (Element)nodes.item(i);
Attr attribute = elem.getAttributeNode(attribute);
attribute.setValue(newValue);
}
}
}
This will update all attribute values of attributes named in elements named in a dom document. Of course, you should add appropriate error handling and null-checks.
PS: You can find all the information in the dom api documentation: http://www.w3.org/2003/01/dom2-javadoc/org/w3c/dom/Document.html