private void OnRemove(XmlElement diffgramElement, XmlDiffPathNodeList matchNodes, XmlDiffViewParentNode sourceParent, ref XmlDiffViewNode currentPosition) { // opid & descriptor XmlDiffViewOperation op = XmlDiffViewOperation.Remove; int opid = 0; OperationDescriptor opDesc = null; string opidAttr = diffgramElement.GetAttribute("opid"); if (opidAttr != string.Empty) { opid = int.Parse(opidAttr); opDesc = GetDescriptor(opid); if (opDesc._type == OperationDescriptor.Type.Move) { op = XmlDiffViewOperation.MoveFrom; } } // subtree string subtreeAttr = diffgramElement.GetAttribute("subtree"); bool bSubtree = (subtreeAttr != "no"); if (!bSubtree) { if (matchNodes.Count != 1) { throw new Exception("The 'match' attribute of 'remove' element must select a single node when the 'subtree' attribute is specified."); } // annotate node matchNodes.MoveNext(); XmlDiffViewNode node = matchNodes.Current; AnnotateNode(node, op, opid, false); if (opid != 0) { opDesc._nodeList.AddNode(node); } // recurse ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)node); } else { // annotate nodes matchNodes.Reset(); while (matchNodes.MoveNext()) { if (opid != 0) { opDesc._nodeList.AddNode(matchNodes.Current); } AnnotateNode(matchNodes.Current, op, opid, true); } } }
private OperationDescriptor GetDescriptor(int opid) { OperationDescriptor opDesc = (OperationDescriptor)_descriptors[opid]; if (opDesc == null) { throw new Exception("Invalid operation id."); } return(opDesc); }
private void OnAddMatch(XmlElement diffgramElement, XmlDiffPathNodeList matchNodes, XmlDiffViewParentNode sourceParent, ref XmlDiffViewNode currentPosition) { string opidAttr = diffgramElement.GetAttribute("opid"); if (opidAttr == string.Empty) { throw new Exception("Missing opid attribute."); } // opid & descriptor int opid = int.Parse(opidAttr); OperationDescriptor opDesc = GetDescriptor(opid); string subtreeAttr = diffgramElement.GetAttribute("subtree"); bool bSubtree = (subtreeAttr != "no"); // move single node without subtree if (!bSubtree) { if (matchNodes.Count != 1) { throw new Exception("The 'match' attribute of 'add' element must select a single node when the 'subtree' attribute is specified."); } // clone node matchNodes.MoveNext(); XmlDiffViewNode newNode = matchNodes.Current.Clone(false); AnnotateNode(newNode, XmlDiffViewOperation.MoveTo, opid, true); opDesc._nodeList.AddNode(newNode); // insert in tree sourceParent.InsertChildAfter(newNode, currentPosition, false); currentPosition = newNode; // recurse ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)newNode); } // move subtree else { matchNodes.Reset(); while (matchNodes.MoveNext()) { XmlDiffViewNode newNode = matchNodes.Current.Clone(true); AnnotateNode(newNode, XmlDiffViewOperation.MoveTo, opid, true); opDesc._nodeList.AddNode(newNode); sourceParent.InsertChildAfter(newNode, currentPosition, false); currentPosition = newNode; } } }
private void PreprocessDiffgram(XmlDocument diffgramDoc) { // read xmldiff options XmlAttribute attr = (XmlAttribute)diffgramDoc.DocumentElement.Attributes.GetNamedItem("options"); if (attr == null) { throw new Exception("Missing 'options' attribute in the diffgram."); } string optionsAttr = attr.Value; var options = XmlDiff.ParseOptions(optionsAttr); _bIgnoreChildOrder = (((int)options & (int)(XmlDiffOptions.IgnoreChildOrder)) > 0); _bIgnoreComments = (((int)options & (int)(XmlDiffOptions.IgnoreComments)) > 0); _bIgnorePI = (((int)options & (int)(XmlDiffOptions.IgnorePI)) > 0); _bIgnoreWhitespace = (((int)options & (int)(XmlDiffOptions.IgnoreWhitespace)) > 0); _bIgnoreNamespaces = (((int)options & (int)(XmlDiffOptions.IgnoreNamespaces)) > 0); _bIgnorePrefixes = (((int)options & (int)(XmlDiffOptions.IgnorePrefixes)) > 0); _bIgnoreDtd = (((int)options & (int)(XmlDiffOptions.IgnoreDtd)) > 0); if (_bIgnoreNamespaces) { _bIgnorePrefixes = true; } // read descriptors XmlNodeList children = diffgramDoc.DocumentElement.ChildNodes; IEnumerator e = children.GetEnumerator(); while (e.MoveNext()) { XmlElement desc = e.Current as XmlElement; if (desc != null && desc.LocalName == "descriptor") { int opid = int.Parse(desc.GetAttribute("opid")); OperationDescriptor.Type type; switch (desc.GetAttribute("type")) { case "move": type = OperationDescriptor.Type.Move; break; case "prefix change": type = OperationDescriptor.Type.PrefixChange; break; case "namespace change": type = OperationDescriptor.Type.NamespaceChange; break; default: throw new Exception("Invalid descriptor type."); } OperationDescriptor od = new OperationDescriptor(opid, type); _descriptors[opid] = od; } } }