You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/09/03 16:56:21 UTC
DO NOT REPLY [Bug 31046] New: -
[configuration] XMLConfiguration.addProperty doesn't create new child nodes
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31046>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31046
[configuration] XMLConfiguration.addProperty doesn't create new child nodes
Summary: [configuration] XMLConfiguration.addProperty doesn't
create new child nodes
Product: Commons
Version: Nightly Builds
Platform: All
OS/Version: All
Status: NEW
Severity: Critical
Priority: Other
Component: Configuration
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: smanux@lfjr.net
Issue reported by Ben Hutchison on the dev list:
XMLConfiguration.addProperty(key, Object) doesn't handle nest keys
properly.
In this loop logic, the full key name is broken into parts, and the DOM
tree is walked. However, if a branch mentioned in the key isn't there,
the loop incorrectly breaks out. Result is that eg addProperty("a.b")
doesn't actually add at "a.b" unless "a" & "b" already exist. Old
version shown:
String[] nodes = parseElementNames(name);
Element element = document.getDocumentElement();
Element parent = element;
for (int i = 0; i < nodes.length; i++) {
if (element == null)
break; //******************** this is not right
**********************
parent = element;
String eName = nodes[i];
Element child = getChildElementWithName(eName, element);
element = child;
}
My tested fix:
Element element = document.getDocumentElement();
Element child = null;
for (int i = 0; i < nodes.length; i++) {
child = getChildElementWithName(nodes[i], element);
if (child == null) {
child = document.createElement(nodes[i]);
element.appendChild(child);
}
element = child;
}
if (attName == null) {
CharacterData data = document.createTextNode(value.toString());
child.appendChild(data);
} else {
child.setAttribute(attName, value.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org