public static XmlDiff Load(string path) { var doc = new XmlDocument(); doc.Load(path); var patch = doc.DocumentElement; var selector = patch.SelectSingleNode("Selectors/Selector"); var modifications = patch.SelectNodes("Modifications/*"); return(new XmlDiff { Selector = XmlSelector.Deserialize(selector), Modifications = modifications.Cast <XmlNode>().Select(n => XmlModification.Deserialize(n)).ToList() }); }
public static XmlSelector Deserialize(XmlNode node) { var xpath = node.SelectSingleNode("@XPath")?.Value; if (string.IsNullOrWhiteSpace(xpath) || !int.TryParse(node.SelectSingleNode("@NodeId")?.Value ?? string.Empty, out var id)) { throw new Exception($"Unable to locate XPath or NodeId attributes on '{node.Name}' node."); } return(new XmlSelector(xpath, id, node.SelectNodes("Selector").Cast <XmlNode>().Select(n => XmlSelector.Deserialize(n)))); }