public void ValidateCode(object sender, RoutedEventArgs e) { object context = Utils.GetDataContext(sender); IEnumerable <XmlNode> data = Utils.GetXmlDataContext(context); if (null != data) { foreach (XmlNode node in data) { XmlNode attr = node.SelectSingleNode("languageCode/@value"); if (null != attr) { string code = attr.Value; if (2 == code.Length) { string threeLetter = LanguageConverter.GetThreeLetterCode(code); if (null != threeLetter) { attr.Value = threeLetter; MetadataEditorControl.UpdateDataContext(this as DependencyObject); } } } break; // just one } } }