public XmlDocument ApplyChanges(BaseDiffResultObjectList results, XmlNode originalDocument) { XmlDocument resultDocument = new XmlDocument(); XPathNavigator navigator = originalDocument.CreateNavigator(); foreach (var item in results.Items) { GetCommonNode(item, ref navigator); } resultDocument.LoadXml(navigator.OuterXml); return resultDocument; }
public XmlDocument GetResultFile(BaseDiffResultObjectList changes, XmlDocument originalNode) { Assert.ArgumentNotNull(originalNode, "Original document can't be null"); return GetResultFile(changes, originalNode.DocumentElement); }
public XmlDocument GetResultFile(BaseDiffResultObjectList changes, string originalNodePath) { Assert.StringIsNullOrEmpty(originalNodePath, "Output File Path is empty"); XmlTextReader originalDocumentReader = new XmlTextReader(new StreamReader(originalNodePath)); XmlDocument originalDocument = new XmlDocument(); originalDocument.Load(originalDocumentReader); originalDocumentReader.Close(); return GetResultFile(changes, originalDocument); }
public XmlDocument GetResultFile(BaseDiffResultObjectList changes, XmlNode originalNode) { Assert.ArgumentNotNull(originalNode, "Original Node can't be null"); return Manager.ApplyChanges(changes, originalNode); }
public BaseDiffResultObjectList DoCompare(XmlNode originalDocument, XmlNode changedDocument, string outputFilePath, XmlDiffOptions options) { Assert.StringIsNullOrEmpty(outputFilePath, "Output File Path is empty"); BaseDiffResultObjectList results = new BaseDiffResultObjectList(); StreamWriter stream = new StreamWriter(outputFilePath, false); XmlTextWriter tw = new XmlTextWriter(stream); tw.Formatting = Formatting.Indented; SetDiffOptions(options); bool isEqual = false; try { isEqual = _diff.Compare(originalDocument, changedDocument, tw); } finally { tw.Close(); stream.Close(); } if (isEqual) { return results; } XmlTextReader diffGram = new XmlTextReader(outputFilePath); XmlDocument diffgramDoc = new XmlDocument(); diffgramDoc.Load(diffGram); Manager.ApplyDiff(diffgramDoc.DocumentElement.FirstChild, originalDocument, ref results); return results; }
public void ApplyDiff(XmlNode diffgramParent, XmlNode sourceParent, ref BaseDiffResultObjectList results) { IEnumerator enumerator = diffgramParent.ChildNodes.GetEnumerator(); XmlNode matchNode = sourceParent; while (enumerator.MoveNext()) { XmlNode current = (XmlNode)enumerator.Current; if (current.NodeType != XmlNodeType.Comment) { XmlElement element = enumerator.Current as XmlElement; if (element == null) { continue; } if (element.NamespaceURI != "http://schemas.microsoft.com/xmltools/2002/xmldiff") { throw new Exception("Invalid element in diffgram."); } string attribute = element.GetAttribute("match"); if (attribute != string.Empty) { int index = 0; if (int.TryParse(attribute, out index)) { matchNode = sourceParent.ChildNodes[index - 1]; } } string localName = element.LocalName; if (localName != null) { localName = string.IsInterned(localName); if (localName == "node") { if (element.ChildNodes.Count > 0) { ApplyDiff(element, matchNode, ref results); } } else { if (localName == "add") { results.OnAdd(element.FirstChild, FindXPath(matchNode), FindXPath(matchNode, true)); continue; } if (localName == "remove") { results.OnRemove(matchNode, FindXPath(matchNode), FindXPath(matchNode, true)); continue; } if (localName == "change") { results.OnChange(matchNode, element.FirstChild, FindXPath(matchNode), FindXPath(matchNode, true)); if (element.ChildNodes.Count > 0) { ApplyDiff(element, matchNode, ref results); } } } } } } }