Menu

#48 Remove Keys and Sections bug

open
nobody
None
5
2008-07-20
2008-07-20
gpraceman
No

If trying to delete multiple keys or sections, only one is deleted.

In XMLConfigSource I had to fix how it was going through each node to determine which ones to remove. Below are the updated methods. The same problem exists in the same methods in DotNetConfigSource.

/// <summary>
/// Removes all XML sections that were removed as configs.
/// </summary>
private void RemoveSections()
{
XmlAttribute attr = null;
XmlNode node;

for (int i = configDoc.DocumentElement.ChildNodes.Count - 1; i > -1; i--) {
node = configDoc.DocumentElement.ChildNodes.Item(i);

if (node.NodeType == XmlNodeType.Element && node.Name == "Section") {
attr = node.Attributes["Name"];

if (attr != null) {
if (this.Configs[attr.Value] == null) {
configDoc.DocumentElement.RemoveChild(node);
}
} else {
throw new ArgumentException("Section name attribute not found");
}
}
}
}

/// <summary>
/// Removes all XML keys that were removed as config keys.
/// </summary>
private void RemoveKeys(string sectionName)
{
XmlNode sectionNode = GetSectionByName(sectionName);
XmlAttribute keyName = null;
XmlNode node;

if (sectionNode != null) {
for (int i = sectionNode.ChildNodes.Count - 1; i > -1; i--) {
node = sectionNode.ChildNodes.Item(i);

if (node.NodeType == XmlNodeType.Element && node.Name == "Key") {
keyName = node.Attributes["Name"];

if (keyName != null) {
if (this.Configs[sectionName].Get(keyName.Value) == null) {
sectionNode.RemoveChild(node);
}
} else {
throw new ArgumentException("Name attribute not found in key");
}
}
}
}
}

Discussion


Log in to post a comment.