// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Xml; namespace E { public class Program { public static void Modify(XmlDocument doc, int val1, int val2, int val3) { XmlElement elm = (XmlElement)doc.SelectSingleNode("//details/detail[t1[1]='" + val1 + "' and t1[2]='" + val2 + "' and t1[3]='" + val3 + "']"); elm.RemoveChild(elm.SelectSingleNode("t1[text()='" + val1 + "']")); elm.RemoveChild(elm.SelectSingleNode("t1[text()='" + val2 + "']")); elm.RemoveChild(elm.SelectSingleNode("t1[text()='" + val3 + "']")); XmlElement t1 = doc.CreateElement("t1"); t1.AppendChild(doc.CreateTextNode(val1 + " or " + val2 + " or " + val3)); elm.AppendChild(t1); } public static void Main(string[] args) { string xml = @"
name 10 100 1000 name 11 111 11111 name 21 221 2221
"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); Modify(doc, 10, 100, 1000); doc.Save(Console.Out); } } }