internal override void DrawHtml(XmlWriter writer, int indent) { if (_op == XmlDiffViewOperation.Change) { XmlDiffViewOperation nameOp = (_name == _changeInfo._localName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change; XmlDiffViewOperation valueOp = (_value == _changeInfo._value) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change; XmlDiffView.HtmlStartRow(writer); XmlDiffView.HtmlStartCell(writer, indent); XmlDiffView.HtmlWriteString(writer, "<?"); XmlDiffView.HtmlWriteString(writer, nameOp, _name); XmlDiffView.HtmlWriteString(writer, " "); XmlDiffView.HtmlWriteString(writer, valueOp, _value); XmlDiffView.HtmlWriteString(writer, "?>"); XmlDiffView.HtmlEndCell(writer); XmlDiffView.HtmlStartCell(writer, indent); XmlDiffView.HtmlWriteString(writer, "<?"); XmlDiffView.HtmlWriteString(writer, nameOp, _changeInfo._localName); XmlDiffView.HtmlWriteString(writer, " "); XmlDiffView.HtmlWriteString(writer, valueOp, _changeInfo._value); XmlDiffView.HtmlWriteString(writer, "?>"); XmlDiffView.HtmlEndCell(writer); XmlDiffView.HtmlEndRow(writer); } else { DrawHtmlNoChange(writer, indent); } }
private void AnnotateNode(XmlDiffViewNode node, XmlDiffViewOperation op, int opid, bool bSubtree) { node._op = op; node._opid = opid; if (node._nodeType == XmlNodeType.Element) { XmlDiffViewAttribute attr = ((XmlDiffViewElement)node)._attributes; while (attr != null) { attr._op = op; attr._opid = opid; attr = (XmlDiffViewAttribute)attr._nextSibbling; } } if (bSubtree) { XmlDiffViewNode childNode = node.FirstChildNode; while (childNode != null) { AnnotateNode(childNode, op, opid, true); childNode = childNode._nextSibbling; } } }
/// <summary> /// Generates output data in text form for a difference due /// to adding data. /// </summary> /// <param name="writer">output stream</param> /// <param name="typeOfDifference">type of difference</param> /// <param name="tagStart">xml tags at start of statement</param> /// <param name="tagEnd">xml tags at end of statement</param> private void DrawHtmlName( XmlWriter writer, XmlDiffViewOperation typeOfDifference, string tagStart, string tagEnd) { if (this.Prefix != string.Empty && this.ignorePrefixes) { XmlDiffView.HtmlWriteString( writer, typeOfDifference, tagStart); XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, this.Prefix + ":"); XmlDiffView.HtmlWriteString( writer, typeOfDifference, this.LocalName + tagEnd); } else { XmlDiffView.HtmlWriteString( writer, typeOfDifference, tagStart + this.Name + tagEnd); } }
private void AnnotateNode( XmlDiffViewNode node, XmlDiffViewOperation op, int opid, bool bSubtree) { node._op = op; node._opid = opid; if (node._nodeType == XmlNodeType.Element) { for (var diffViewAttribute = ((XmlDiffViewElement)node)._attributes; diffViewAttribute != null; diffViewAttribute = (XmlDiffViewAttribute)diffViewAttribute._nextSibbling) { diffViewAttribute._op = op; diffViewAttribute._opid = opid; } } if (!bSubtree) { return; } for (var node1 = node.FirstChildNode; node1 != null; node1 = node1._nextSibbling) { this.AnnotateNode(node1, op, opid, true); } }
/// <summary> /// Generate html output data for a differences /// due to a change in an attribute. /// </summary> /// <param name="writer">output stream</param> /// <param name="attr">Attribute object</param> /// <param name="typeOfDifference">type of difference</param> public void DrawHtmlAttribute( XmlWriter writer, bool ignorePrefixes, XmlDiffViewOperation typeOfDifference) { bool opid = false; if (this.OperationId != XmlDiffView.LastVisitedOpId) { XmlDiffView.LastVisitedOpId = this.OperationId; // only write this anchor if the parent elemnt was not also changed. if (this.OperationId != 0 && this.Parent.Operation != this.Operation && (this.PreviousSibling == null || this.PreviousSibling.Operation != this.Operation)) { writer.WriteStartElement("a"); writer.WriteAttributeString("name", "id" + this.OperationId); opid = true; } } if (ignorePrefixes) { if (this.Prefix == "xmlns" || (this.LocalName == "xmlns" && this.Prefix == string.Empty)) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, this.Name); XmlDiffView.HtmlWriteString( writer, typeOfDifference, "=\"" + this.AttributeValue + "\""); return; } else if (this.Prefix != string.Empty) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, this.Prefix + ":"); XmlDiffView.HtmlWriteString( writer, typeOfDifference, this.LocalName + "=\"" + this.AttributeValue + "\""); return; } } XmlDiffView.HtmlWriteString( writer, typeOfDifference, this.Name + "=\"" + this.AttributeValue + "\""); if (opid) { writer.WriteEndElement(); } }
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 void DrawHtmlName(XmlWriter writer, XmlDiffViewOperation opForColor, string tagStart, string tagEnd) { if (_prefix != string.Empty && _ignorePrefixes) { XmlDiffView.HtmlWriteString(writer, opForColor, tagStart); XmlDiffView.HtmlWriteString(writer, XmlDiffViewOperation.Ignore, _prefix + ":"); XmlDiffView.HtmlWriteString(writer, opForColor, _localName + tagEnd); } else { XmlDiffView.HtmlWriteString(writer, opForColor, tagStart + _name + tagEnd); } }
/// <summary> /// Generates output data in html form. /// </summary> /// <param name="writer">output data stream</param> /// <param name="indent">size of indentation</param> internal override void DrawHtml(XmlWriter writer, int indent) { if (Operation == XmlDiffViewOperation.Change) { XmlDiffViewOperation nameOp = (this.Name == ChangeInformation.LocalName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change; XmlDiffViewOperation valueOp = (this.InnerText == ChangeInformation.Subset) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change; XmlDiffView.HtmlStartRow(writer); this.DrawLineNumber(writer); XmlDiffView.HtmlStartCell(writer, indent); XmlDiffView.HtmlWriteString(writer, Tags.XmlErrorHandlingBegin); XmlDiffView.HtmlWriteString(writer, nameOp, this.Name); XmlDiffView.HtmlWriteString(writer, " "); XmlDiffView.HtmlWriteString( writer, valueOp, RemoveTabsAndNewlines(InnerText)); XmlDiffView.HtmlWriteString(writer, Tags.XmlErrorHandlingEnd); XmlDiffView.HtmlEndCell(writer); XmlDiffView.HtmlStartCell(writer, indent); XmlDiffView.HtmlWriteString(writer, Tags.XmlErrorHandlingBegin); XmlDiffView.HtmlWriteString( writer, nameOp, ChangeInformation.LocalName); XmlDiffView.HtmlWriteString(writer, " "); XmlDiffView.HtmlWriteString( writer, valueOp, RemoveTabsAndNewlines(ChangeInformation.Subset)); XmlDiffView.HtmlWriteString(writer, Tags.XmlErrorHandlingEnd); XmlDiffView.HtmlEndCell(writer); XmlDiffView.HtmlEndRow(writer); } else { DrawHtmlNoChange(writer, indent); } }
private void DrawHtmlAttribute(XmlWriter writer, XmlDiffViewAttribute attr, XmlDiffViewOperation opForColor) { if (_ignorePrefixes) { if (attr._prefix == "xmlns" || (attr._localName == "xmlns" && attr._prefix == string.Empty)) { XmlDiffView.HtmlWriteString(writer, XmlDiffViewOperation.Ignore, attr._name); XmlDiffView.HtmlWriteString(writer, opForColor, "=\"" + attr._value + "\""); return; } else if (attr._prefix != string.Empty) { XmlDiffView.HtmlWriteString(writer, XmlDiffViewOperation.Ignore, attr._prefix + ":"); XmlDiffView.HtmlWriteString(writer, opForColor, attr._localName + "=\"" + attr._value + "\""); return; } } XmlDiffView.HtmlWriteString(writer, opForColor, attr._name + "=\"" + attr._value + "\""); }
/// <summary> /// Generate html output data for a differences /// due to a change in an attribute. /// </summary> /// <param name="writer">output stream</param> /// <param name="attr">Attribute object</param> /// <param name="typeOfDifference">type of difference</param> private void DrawHtmlAttribute( XmlWriter writer, XmlDiffViewAttribute attr, XmlDiffViewOperation typeOfDifference) { if (this.ignorePrefixes) { if (attr.Prefix == "xmlns" || (attr.LocalName == "xmlns" && attr.Prefix == string.Empty)) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, attr.Name); XmlDiffView.HtmlWriteString( writer, typeOfDifference, "=\"" + attr.AttributeValue + "\""); return; } else if (attr.Prefix != string.Empty) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, attr.Prefix + ":"); XmlDiffView.HtmlWriteString( writer, typeOfDifference, attr.LocalName + "=\"" + attr.AttributeValue + "\""); return; } } XmlDiffView.HtmlWriteString( writer, typeOfDifference, attr.Name + "=\"" + attr.AttributeValue + "\""); }
static internal void HtmlWriteString(XmlWriter pane, XmlDiffViewOperation op, string str) { HtmlSetColor(pane, op); pane.WriteString(str); HtmlResetColor(pane); }
/// <summary> /// Generate text output data for a differences /// due to a change, which may or may not have been /// a change in the attribute. /// </summary> /// <param name="writer">output stream</param> /// <param name="attr">Attribute object</param> private void DrawTextAttributeChange( TextWriter writer, XmlDiffViewAttribute attr) { Debug.Assert(null != attr); if (this.Prefix != string.Empty) { //if the prefix changed then show the change XmlDiffViewOperation op = this.ignorePrefixes ? XmlDiffViewOperation.Ignore : (attr.Prefix == attr.ChangeInformation.Prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change; switch (op) { case XmlDiffViewOperation.Ignore: case XmlDiffViewOperation.Match: writer.Write(attr.Prefix + ":"); break; case XmlDiffViewOperation.Change: // show the new prefix writer.Write( Difference.Tag + "=" + Difference.ChangeBegin + attr.Prefix + Difference.ChangeTo + attr.ChangeInformation.Prefix + Difference.ChangeEnd); writer.Write(attr.ChangeInformation.Prefix + ":"); break; default: Trace.WriteLine("Unexpected type of difference"); throw new ArgumentException( "Unexpected type of difference", "Operation"); } } if (System.Diagnostics.Debugger.IsAttached) { string debugMessage = "It is not appropriate to call this function" + "when the ChangeInformation object is null."; Debug.Assert( null != attr.ChangeInformation, debugMessage); } // something changed if (attr.LocalName != attr.ChangeInformation.LocalName) { // show the change in the name writer.Write(" " + attr.LocalName + "=\"" + Difference.Tag + "RenamedNode" + Difference.ChangeTo + attr.ChangeInformation.LocalName + Difference.ChangeEnd + "="); } else { writer.Write(" " + attr.LocalName + "=\""); } // determine if the attribute value has changed if (attr.AttributeValue != attr.ChangeInformation.Subset) { // attribute value changed //Note: "xd_ChangeFrom('original value')To('new value')" string attributeValueChange = Difference.Tag + Difference.ChangeBegin + attr.AttributeValue + Difference.ChangeTo + RemoveTabsAndNewlines(attr.ChangeInformation.Subset) + Difference.ChangeEnd; writer.Write(attributeValueChange + "\""); } else { // attribute value is same writer.Write( RemoveTabsAndNewlines(attr.AttributeValue) + "\""); } }
static private void HtmlSetColor(XmlWriter pane, XmlDiffViewOperation op) { pane.WriteStartElement("font"); pane.WriteAttributeString("style", HtmlBgColor[(int)op]); pane.WriteAttributeString("color", HtmlFgColor[(int)op]); }
/// <summary> /// Writes to the specified section using /// highlighting based on hte type of data change /// </summary> /// <param name="pane">baseline/actual data presentation sections</param> /// <param name="op">Type of data change</param> /// <param name="str">Statement to be written</param> internal static void HtmlWriteString( XmlWriter pane, XmlDiffViewOperation op, string str) { HtmlSetColor(pane, op); pane.WriteString(str); HtmlResetColor(pane); }
/// <summary> /// Sets the output style based on the type of change in the data. /// </summary> /// <param name="pane">baseline/actual data presentation sections</param> /// <param name="op">Type of data change</param> private static void HtmlSetColor( XmlWriter pane, XmlDiffViewOperation op) { pane.WriteStartElement("span"); pane.WriteAttributeString("class", op.ToString().ToLowerInvariant()); }
/// <summary> /// Mark the nodes (and attributes) with the type of data change /// </summary> /// <param name="node">the node to annotate</param> /// <param name="op">the type of data change</param> /// <param name="opid">the operation identification number</param> /// <param name="subtree">the node's subtree</param> private void AnnotateNode( XmlDiffViewNode node, XmlDiffViewOperation op, int opid, bool subtree) { node.Operation = op; node.OperationId = opid; if (node.NodeType == XmlNodeType.Element) { XmlDiffViewAttribute attr = ( (XmlDiffViewElement)node).Attributes; while (attr != null) { attr.Operation = op; attr.OperationId = opid; attr = (XmlDiffViewAttribute)attr.NextSibbling; } } if (subtree) { XmlDiffViewNode childNode = node.FirstChildNode; while (childNode != null) { this.AnnotateNode(childNode, op, opid, true); childNode = childNode.NextSibbling; } } }
private void DrawHtmlAttribute( XmlWriter writer, XmlDiffViewAttribute attr, XmlDiffViewOperation opForColor ) { if ( _ignorePrefixes ) { if ( attr._prefix == "xmlns" || ( attr._localName == "xmlns" && attr._prefix == string.Empty ) ) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, attr._name ); XmlDiffView.HtmlWriteString( writer, opForColor , "=\"" + attr._value + "\"" ); return; } else if ( attr._prefix != string.Empty ) { XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, attr._prefix + ":" ); XmlDiffView.HtmlWriteString( writer, opForColor , attr._localName + "=\"" + attr._value + "\"" ); return; } } XmlDiffView.HtmlWriteString( writer, opForColor , attr._name + "=\"" + attr._value + "\"" ); }
internal override void DrawHtml(XmlWriter writer, int indent) { XmlDiffViewOperation opForColor = _op; bool bCloseElement = false; XmlDiffView.HtmlStartRow(writer); for (int i = 0; i < 2; i++) { XmlDiffView.HtmlStartCell(writer, indent); if (XmlDiffView.HtmlWriteToPane[(int)_op, i]) { bCloseElement = OutputNavigation(writer); if (_op == XmlDiffViewOperation.Change) { opForColor = XmlDiffViewOperation.Match; XmlDiffView.HtmlWriteString(writer, opForColor, "<"); if (i == 0) { DrawHtmlNameChange(writer, _localName, _prefix); } else { DrawHtmlNameChange(writer, _changeInfo._localName, _changeInfo._prefix); } } else { DrawHtmlName(writer, opForColor, "<", string.Empty); } if (bCloseElement) { writer.WriteEndElement(); bCloseElement = false; } // attributes DrawHtmlAttributes(writer, i); // close start tag if (_childNodes != null) { XmlDiffView.HtmlWriteString(writer, opForColor, ">"); } else { XmlDiffView.HtmlWriteString(writer, opForColor, "/>"); } } else { XmlDiffView.HtmlWriteEmptyString(writer); } XmlDiffView.HtmlEndCell(writer); } XmlDiffView.HtmlEndRow(writer); // child nodes if (_childNodes != null) { HtmlDrawChildNodes(writer, indent + XmlDiffView.DeltaIndent); // end element XmlDiffView.HtmlStartRow(writer); for (int i = 0; i < 2; i++) { XmlDiffView.HtmlStartCell(writer, indent); if (XmlDiffView.HtmlWriteToPane[(int)_op, i]) { if (_op == XmlDiffViewOperation.Change) { Debug.Assert(opForColor == XmlDiffViewOperation.Match); XmlDiffView.HtmlWriteString(writer, opForColor, "</"); if (i == 0) { DrawHtmlNameChange(writer, _localName, _prefix); } else { DrawHtmlNameChange(writer, _changeInfo._localName, _changeInfo._prefix); } XmlDiffView.HtmlWriteString(writer, opForColor, ">"); } else { DrawHtmlName(writer, opForColor, "</", ">"); } } else { XmlDiffView.HtmlWriteEmptyString(writer); } XmlDiffView.HtmlEndCell(writer); } XmlDiffView.HtmlEndRow(writer); } }
/// <summary> /// Generates output data in html form /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> internal override void DrawHtml(XmlWriter writer, int indent) { XmlDiffViewOperation typeOfDifference = Operation; bool closeElement = false; XmlDiffView.HtmlStartRow(writer); this.DrawLinkNode(writer); for (int i = 0; i < 2; i++) { XmlDiffView.HtmlStartCell(writer, indent); if (XmlDiffView.HtmlWriteToPane[(int)Operation, i]) { closeElement = OutputNavigationHtml(writer); if (Operation == XmlDiffViewOperation.Change) { typeOfDifference = XmlDiffViewOperation.Match; XmlDiffView.HtmlWriteString( writer, typeOfDifference, Tags.XmlOpenBegin); if (i == 0) { this.DrawHtmlNameChange( writer, this.LocalName, this.Prefix); } else { this.DrawHtmlNameChange( writer, ChangeInformation.LocalName, ChangeInformation.Prefix); } } else { this.DrawHtmlName( writer, typeOfDifference, Tags.XmlOpenBegin, string.Empty); } if (closeElement) { // write the closing '</A>' tag. writer.WriteEndElement(); closeElement = false; } // attributes this.DrawHtmlAttributes(writer, i); // close start tag if (ChildNodes != null) { XmlDiffView.HtmlWriteString( writer, typeOfDifference, Tags.XmlOpenEnd); } else { XmlDiffView.HtmlWriteString( writer, typeOfDifference, Tags.XmlOpenEndTerse); } } else { XmlDiffView.HtmlWriteEmptyString(writer); } XmlDiffView.HtmlEndCell(writer); } XmlDiffView.HtmlEndRow(writer); // child nodes if (ChildNodes != null) { HtmlDrawChildNodes(writer, indent + XmlDiffView.DeltaIndent); // end element XmlDiffView.HtmlStartRow(writer); this.DrawLinkNode(writer); for (int i = 0; i < 2; i++) { XmlDiffView.HtmlStartCell(writer, indent); if (XmlDiffView.HtmlWriteToPane[(int)Operation, i]) { if (Operation == XmlDiffViewOperation.Change) { Debug.Assert(typeOfDifference == XmlDiffViewOperation.Match); XmlDiffView.HtmlWriteString( writer, typeOfDifference, Tags.XmlCloseBegin); if (i == 0) { this.DrawHtmlNameChange( writer, this.LocalName, this.Prefix); } else { this.DrawHtmlNameChange( writer, ChangeInformation.LocalName, ChangeInformation.Prefix); } XmlDiffView.HtmlWriteString( writer, typeOfDifference, Tags.XmlOpenEnd); } else { this.DrawHtmlName( writer, typeOfDifference, Tags.XmlCloseBegin, Tags.XmlCloseEnd); } } else { XmlDiffView.HtmlWriteEmptyString(writer); } XmlDiffView.HtmlEndCell(writer); } XmlDiffView.HtmlEndRow(writer); } }
private void DrawHtmlName( XmlWriter writer, XmlDiffViewOperation opForColor, string tagStart, string tagEnd ) { if ( _prefix != string.Empty && _ignorePrefixes ) { XmlDiffView.HtmlWriteString( writer, opForColor, tagStart ); XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Ignore, _prefix + ":" ); XmlDiffView.HtmlWriteString( writer, opForColor, _localName + tagEnd ); } else { XmlDiffView.HtmlWriteString( writer, opForColor, tagStart + _name + tagEnd ); } }