/// <summary> /// Generate output text for a difference due to a change /// to the baseline data. /// </summary> /// <param name="writer">output data stream</param> /// <param name="indent">size of the indent</param> public void DrawTextNoChange( TextWriter writer, int indent) { Debug.Assert(this.NodeType != XmlNodeType.Element && this.NodeType != XmlNodeType.Attribute); Debug.Assert(this.Operation != XmlDiffViewOperation.Change); //bool closeElement = OutputNavigationHtml(writer); string xmlText = this.OuterXml; writer.Write(XmlDiffView.IndentText(indent) + xmlText); }
/// <summary> /// Generates atrributes' output data in text form /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> private void DrawTextAttributes( TextWriter writer, int indent) { if (this.Attributes != null) { indent += Indent.IncrementSize; XmlDiffViewAttribute curAttr = this.Attributes; while (curAttr != null) { if (curAttr == this.Attributes) { writer.Write(" "); } else { // put subsequent attributes on their own line writer.Write( writer.NewLine + XmlDiffView.IndentText(indent)); } // The attributes could have their own // 'add'/'remove'/'move from'/ 'move to'/match/ignore // attribute operations so we check for that now switch (curAttr.Operation) { case XmlDiffViewOperation.Change: this.DrawTextAttributeChange(writer, curAttr); break; case XmlDiffViewOperation.Add: case XmlDiffViewOperation.Ignore: case XmlDiffViewOperation.MoveFrom: case XmlDiffViewOperation.MoveTo: case XmlDiffViewOperation.Remove: case XmlDiffViewOperation.Match: // for 'add'/'remove'/'move from'/'move to'/match // operations write out the baseline attributes // data. this.DrawTextAttribute(writer, curAttr); break; default: // raise exception for new type of // difference created in XmlDiff object. throw new ArgumentException( "Unrecognised type of difference", "Operation"); } curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling; } } }
/// <summary> /// Generates output data in text form for differences /// due to adding data /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> private void DrawTextAdd( TextWriter writer, int indent) { writer.Write(Tags.XmlDocumentTypeBegin + this.Name + this.DocumentTypeSudoAttributes() + "[" + writer.NewLine + XmlDiffView.IndentText(indent + indent) + Tags.XmlCommentOldStyleBegin + " " + Difference.Tag + Difference.DocumentTypeAdded + " " + Tags.XmlCommentOldStyleEnd + writer.NewLine + this.internalDtdSubset + writer.NewLine + "]" + Tags.XmlDocumentTypeEnd); }
/// <summary> /// Generates output data in text form for a difference due /// to deleting data. /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> /// <param name="tagStart">xml tags at start of statement</param> /// <param name="tagEnd">xml tags at end of statement</param> private void DrawTextNameDelete( TextWriter writer, int indent, string tagStart, string tagEnd) { writer.Write(XmlDiffView.IndentText(indent) + tagStart); if (this.Prefix != string.Empty) { writer.Write(this.Prefix + ":"); } writer.Write(this.LocalName + " " + Difference.Tag + Difference.NodeDeleted); writer.Write(tagEnd); }
/// <summary> /// Generates output data in text form /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> internal override void DrawText(TextWriter writer, int indent) { Debug.Assert(XmlNodeType.Comment == NodeType || XmlNodeType.CDATA == NodeType || XmlNodeType.Text == NodeType); // indent the text. writer.Write(XmlDiffView.IndentText(indent)); switch (Operation) { case XmlDiffViewOperation.Add: this.DrawTextAdd(writer); break; case XmlDiffViewOperation.Change: this.DrawTextChange(writer); break; case XmlDiffViewOperation.Ignore: // suppress the output break; case XmlDiffViewOperation.Match: DrawTextNoChange(writer, indent); break; case XmlDiffViewOperation.MoveFrom: Debug.Assert(false); break; case XmlDiffViewOperation.MoveTo: Debug.Assert(false); break; case XmlDiffViewOperation.Remove: this.DrawTextDelete(writer); break; default: Debug.Assert(false); break; } }
/// <summary> /// Generates output data in text form for a difference due /// to moving data to a new location. /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> /// <param name="tagStart">xml tags at start of statement</param> /// <param name="tagEnd">xml tags at end of statement</param> private void DrawTextNameMoveTo( TextWriter writer, int indent, string tagStart, string tagEnd) { writer.Write(XmlDiffView.IndentText(indent) + tagStart); if (this.Prefix == string.Empty) { writer.Write(this.Prefix + ":"); } writer.Write(this.LocalName + " " + Difference.Tag + Difference.NodeMovedToBegin + OperationId + Difference.NodeMovedToEnd); writer.Write(tagEnd); }
/// <summary> /// Generates output data in text form for the name of the element. /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> /// <param name="tagStart">xml tags at start of statement</param> /// <param name="tagEnd">xml tags at end of statement</param> private void DrawTextName( TextWriter writer, int indent, string tagStart, string tagEnd) { if (this.Prefix != string.Empty && this.ignorePrefixes) { writer.Write( XmlDiffView.IndentText(indent) + tagStart + this.Prefix + ":" + this.LocalName + tagEnd); } else { writer.Write(XmlDiffView.IndentText(indent) + tagStart + this.Name + tagEnd); } }
/// <summary> /// Generates output data in text form for a difference due /// to changing existing data. /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> /// <param name="tagStart">xml tags at start of statement</param> /// <param name="tagEnd">xml tags at end of statement</param> private void DrawTextNameChange( TextWriter writer, int indent, string tagStart, string tagEnd) { writer.Write(XmlDiffView.IndentText(indent) + tagStart); if (this.Prefix != string.Empty) { writer.Write(this.Prefix + ":"); } writer.Write(Difference.Tag + Difference.ChangeBegin + this.LocalName + Difference.ChangeTo + ChangeInformation.LocalName + Difference.ChangeEnd); writer.Write(tagEnd); }
/// <summary> /// Add the DocumentType data to the output. /// </summary> /// <param name="writer">Output data stream</param> /// <param name="indent">current size of text indentation</param> /// <remarks>If the DOCTYPE declaration includes /// declarations that are to be combined with /// external files or the external subset, it /// uses the following syntax. /// DOCTYPE rootElement SYSTEM "URIreference" /// [declarations] /// or /// DOCTYPE rootElement PUBLIC "PublicIdentifier" "URIreference" /// [declarations] /// </remarks> internal override void DrawText(TextWriter writer, int indent) { Debug.Assert(NodeType == XmlNodeType.DocumentType); // indent the text. writer.Write(XmlDiffView.IndentText(indent)); switch (Operation) { case XmlDiffViewOperation.Add: this.DrawTextAdd(writer, indent); break; case XmlDiffViewOperation.Change: this.DrawTextChange(writer, indent); break; case XmlDiffViewOperation.Ignore: case XmlDiffViewOperation.MoveFrom: this.DrawTextMoveFrom(writer, indent); break; case XmlDiffViewOperation.MoveTo: this.DrawTextMoveTo(writer, indent); break; case XmlDiffViewOperation.Match: // for 'Ignore' and match operations // write out the baseline data this.DrawTextNoChange(writer, indent); break; case XmlDiffViewOperation.Remove: this.DrawTextRemove(writer, indent); break; default: Debug.Assert(false); break; } writer.Write(writer.NewLine); }
/// <summary> /// Generates output data in text form for differences /// due to removing data /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> private void DrawTextRemove( TextWriter writer, int indent) { // generate the dtd name and sudo-attributes writer.Write(Tags.XmlDocumentTypeBegin + this.Name + this.DocumentTypeSudoAttributes() + "[" + writer.NewLine); // generate the main body of the dtd. writer.Write(XmlDiffView.IndentText(indent + indent)); // include a comment about the difference. writer.Write(Tags.XmlCommentOldStyleBegin + " " + Difference.Tag + Difference.DocumentTypeDeleted + " " + Tags.XmlCommentOldStyleEnd + writer.NewLine); // include main body and closing tags writer.Write(XmlDiffView.IndentText(indent + indent) + this.internalDtdSubset + writer.NewLine + XmlDiffView.IndentText(indent + indent) + "]" + Tags.XmlDocumentTypeEnd); }
/// <summary> /// Generates output data in text form. /// </summary> /// <param name="writer">output data stream</param> /// <param name="indent">size of indentation</param> internal override void DrawText(TextWriter writer, int indent) { Debug.Assert(XmlNodeType.ProcessingInstruction == NodeType); writer.Write(XmlDiffView.IndentText(indent)); switch (Operation) { case XmlDiffViewOperation.Add: // component name is the new writer.Write(Tags.XmlErrorHandlingBegin + this.Name + " "); // add difference attribute writer.Write(Difference.Tag + Difference.PIAdded); // process other attributes this.DrawAttributes(writer, indent); // close tag writer.Write(Tags.XmlErrorHandlingEnd); break; case XmlDiffViewOperation.Change: { // Determine nature of changes if (this.Name == ChangeInformation.LocalName) { // component name is the same writer.Write(Tags.XmlErrorHandlingBegin + this.Name + " "); // process attributes this.DrawAttributes(writer, indent); // close tag writer.Write(Tags.XmlErrorHandlingEnd); } else { // component name changed //Note: <?{new name of component} xd_="Rename(component)From('original name')" [, {attributes, values} ?> writer.Write(Tags.XmlErrorHandlingBegin + ChangeInformation.LocalName + " "); writer.Write(Difference.Tag + "=" + Difference.PIRenamedBegin + this.Name + Difference.PIRenamedEnd); // process attributes this.DrawAttributes(writer, indent); // close tag writer.Write(Tags.XmlErrorHandlingEnd); } writer.Write(writer.NewLine); } break; case XmlDiffViewOperation.Ignore: Debug.Assert(false); break; case XmlDiffViewOperation.Match: DrawTextNoChange(writer, indent); break; case XmlDiffViewOperation.MoveFrom: Debug.Assert(false); break; case XmlDiffViewOperation.MoveTo: Debug.Assert(false); break; case XmlDiffViewOperation.Remove: // component removed writer.Write(Tags.XmlErrorHandlingBegin + this.Name + " "); // add difference attribute writer.Write(Difference.Tag + Difference.PIDeleted); // process other attributes this.DrawAttributes(writer, indent); // close tag writer.Write(Tags.XmlErrorHandlingEnd); break; default: Debug.Assert(false); break; } writer.Write(writer.NewLine); }
/// <summary> /// Generates output data in text form /// </summary> /// <param name="writer">output stream</param> /// <param name="indent">number of indentations</param> internal override void DrawText( TextWriter writer, int indent) { Debug.Assert(XmlNodeType.XmlDeclaration == NodeType); writer.Write(XmlDiffView.IndentText(indent)); switch (Operation) { case XmlDiffViewOperation.Add: //Note: Can only have one valid declaration // in an Xml document and it must be on // the first line if it is present // component name is the new writer.Write(Tags.XmlDeclarationBegin); // add difference attribute writer.Write(Difference.Tag + Difference.DeclarationAdded); // process sudo-attributes //DrawAttributes(writer, indent); writer.Write(this.declarationValue); // close tag writer.Write(Tags.XmlDeclarationEnd); break; case XmlDiffViewOperation.Change: Debug.Assert(this.declarationValue != ChangeInformation.Subset); // component name is the same writer.Write(Tags.XmlDeclarationBegin); // process attributes //DrawAttributes(writer, indent); //Note: the following breaks xml validation but // could not design a better alternative. writer.Write(Difference.Tag + Difference.ChangeBegin + this.declarationValue + Difference.ChangeTo + ChangeInformation.Subset + Difference.ChangeEnd); // close tag writer.Write(Tags.XmlDeclarationEnd); break; case XmlDiffViewOperation.Ignore: // suppress the output break; case XmlDiffViewOperation.Match: DrawTextNoChange(writer, indent); break; case XmlDiffViewOperation.MoveFrom: Debug.Assert(false); break; case XmlDiffViewOperation.MoveTo: Debug.Assert(false); break; case XmlDiffViewOperation.Remove: // component removed writer.Write(Tags.XmlDeclarationBegin); // add difference attribute writer.Write(Difference.Tag + Difference.DeclarationDeleted); // process sudo-attributes //DrawAttributes(writer, indent); writer.Write(this.declarationValue); // close tag writer.Write(Tags.XmlDeclarationEnd); break; default: Debug.Assert(false); break; } writer.Write(writer.NewLine); }