コード例 #1
0
 /// <summary>
 /// Generate text output data for an unchanged attribute.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="attr">attribute object</param>
 private void DrawTextAttribute(
     TextWriter writer,
     XmlDiffViewAttribute attr)
 {
     if (this.ignorePrefixes)
     {
         if (attr.Prefix == "xmlns" || (attr.LocalName == "xmlns" &&
                                        attr.Prefix == string.Empty))
         {
             writer.Write(attr.Name);
             writer.Write("='" +
                          RemoveTabsAndNewlines(attr.AttributeValue) + "'");
             return;
         }
         else if (attr.Prefix != string.Empty)
         {
             writer.Write(attr.Prefix + ":");
             writer.Write(attr.LocalName + "=\"" +
                          RemoveTabsAndNewlines(attr.AttributeValue) + "\"");
             return;
         }
     }
     writer.Write(attr.Name + "=\"" +
                  RemoveTabsAndNewlines(attr.AttributeValue) + "\"");
 }
コード例 #2
0
        private void DrawHtmlAttributeChange(XmlWriter writer, XmlDiffViewAttribute attr, string localName, string prefix, string value)
        {
            if (prefix != string.Empty)
            {
                XmlDiffView.HtmlWriteString(writer,
                                            _ignorePrefixes ? XmlDiffViewOperation.Ignore :
                                            (attr._prefix == attr._changeInfo._prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                                            prefix + ":");
            }

            XmlDiffView.HtmlWriteString(writer,
                                        (attr._localName == attr._changeInfo._localName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                                        localName);

            if (attr._value != attr._changeInfo._value)
            {
                XmlDiffView.HtmlWriteString(writer, "=\"");
                XmlDiffView.HtmlWriteString(writer, XmlDiffViewOperation.Change, value);
                XmlDiffView.HtmlWriteString(writer, "\"");
            }
            else
            {
                XmlDiffView.HtmlWriteString(writer, "=\"" + value + "\"");
            }
        }
コード例 #3
0
 /// <summary>
 /// Gets a list of the attributes for the specifed node
 /// and if applicable, its children.
 /// </summary>
 /// <param name="parentElement">The node which
 /// contains the attributes</param>
 /// <returns>List of attributes</returns>
 private static XmlDiffPathNodeList SelectAllAttributes(
     XmlDiffViewElement parentElement)
 {
     if (parentElement.Attributes == null)
     {
         OnNoMatchingNode("@*");
         return(null);
     }
     else if (parentElement.Attributes.NextSibling == null)
     {
         XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
         nodeList.AddNode(parentElement.Attributes);
         return(nodeList);
     }
     else
     {
         XmlDiffPathNodeList  nodeList = new XmlDiffPathMultiNodeList();
         XmlDiffViewAttribute curAttr  = parentElement.Attributes;
         while (curAttr != null)
         {
             nodeList.AddNode(curAttr);
         }
         return(nodeList);
     }
 }
コード例 #4
0
        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;
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Inserts an attribute object after the specified attribute object.
 /// </summary>
 /// <param name="newAttr">the attribute object to insert</param>
 /// <param name="refAttr">attribute object to insert after</param>
 public void InsertAttributeAfter(
     XmlDiffViewAttribute newAttr,
     XmlDiffViewAttribute refAttr)
 {
     Debug.Assert(newAttr != null);
     if (refAttr == null)
     {
         // make it the head of the list.
         newAttr.NextSibling = this.Attributes;
         if (this.Attributes != null)
         {
             this.Attributes.PreviousSibling = newAttr;
         }
         this.Attributes = newAttr;
     }
     else
     {
         newAttr.NextSibling = refAttr.NextSibling;
         if (refAttr.NextSibling != null)
         {
             refAttr.NextSibling.PreviousSibling = newAttr;
         }
         newAttr.PreviousSibling = refAttr;
         refAttr.NextSibling     = newAttr;
     }
     newAttr.Parent = this;
 }
コード例 #6
0
        private void DrawHtmlAttributes(XmlWriter writer, int paneNo)
        {
            if (_attributes == null)
            {
                return;
            }

            string attrIndent = string.Empty;

            if (_attributes._nextSibbling != null)
            {
                attrIndent = XmlDiffView.GetIndent(_name.Length + 2);
            }
            XmlDiffViewAttribute curAttr = _attributes;

            while (curAttr != null)
            {
                if (XmlDiffView.HtmlWriteToPane[(int)curAttr._op, paneNo])
                {
                    if (curAttr == _attributes)
                    {
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteRaw(attrIndent);
                    }

                    if (curAttr._op == XmlDiffViewOperation.Change)
                    {
                        if (paneNo == 0)
                        {
                            DrawHtmlAttributeChange(writer, curAttr, curAttr._localName, curAttr._prefix, curAttr._value);
                        }
                        else
                        {
                            DrawHtmlAttributeChange(writer, curAttr, curAttr._changeInfo._localName, curAttr._changeInfo._prefix,
                                                    curAttr._changeInfo._value);
                        }
                    }
                    else
                    {
                        DrawHtmlAttribute(writer, curAttr, curAttr._op);
                    }
                }
                else
                {
                    XmlDiffView.HtmlWriteEmptyString(writer);
                }

                curAttr = (XmlDiffViewAttribute)curAttr._nextSibbling;
                if (curAttr != null)
                {
                    XmlDiffView.HtmlBr(writer);
                }
            }
        }
コード例 #7
0
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode newNode = null;

            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                XmlElement         el         = (XmlElement)node;
                XmlDiffViewElement newElement = new XmlDiffViewElement(el.LocalName, el.Prefix, el.NamespaceURI, _bIgnorePrefixes);
                // attributes
                IEnumerator          attributes  = node.Attributes.GetEnumerator();
                XmlDiffViewAttribute lastNewAttr = null;
                while (attributes.MoveNext())
                {
                    XmlAttribute         at      = (XmlAttribute)attributes.Current;
                    XmlDiffViewAttribute newAttr = new XmlDiffViewAttribute(at.LocalName, at.Prefix, at.NamespaceURI, at.Value);
                    newElement.InsertAttributeAfter(newAttr, lastNewAttr);
                    lastNewAttr = newAttr;
                }
                // children
                IEnumerator     childNodes       = node.ChildNodes.GetEnumerator();
                XmlDiffViewNode lastNewChildNode = null;
                while (childNodes.MoveNext())
                {
                    XmlDiffViewNode newChildNode = ImportNode((XmlNode)childNodes.Current);
                    newElement.InsertChildAfter(newChildNode, lastNewChildNode, false);
                    lastNewChildNode = newChildNode;
                }
                newNode = newElement;
                break;

            case XmlNodeType.Text:
            case XmlNodeType.CDATA:
            case XmlNodeType.Comment:
                newNode = new XmlDiffViewCharData(node.Value, node.NodeType);
                break;

            case XmlNodeType.ProcessingInstruction:
                newNode = new XmlDiffViewPI(node.Name, node.Value);
                break;

            case XmlNodeType.EntityReference:
                newNode = new XmlDiffViewER(node.Name);
                break;

            default:
                Debug.Assert(false, "Invalid node type.");
                break;
            }
            Debug.Assert(newNode != null);
            return(newNode);
        }
コード例 #8
0
        static XmlDiffPathNodeList SelectAttributes(XmlDiffViewElement parentElement, string path)
        {
            Debug.Assert(path[0] == '@');

            int pos = 1;
            XmlDiffPathNodeList nodeList = null;

            for (;;)
            {
                string name = ReadAttrName(path, ref pos);

                if (nodeList == null)
                {
                    if (pos == path.Length)
                    {
                        nodeList = new XmlDiffPathSingleNodeList();
                    }
                    else
                    {
                        nodeList = new XmlDiffPathMultiNodeList();
                    }
                }

                XmlDiffViewAttribute attr = parentElement.GetAttribute(name);
                if (attr == null)
                {
                    OnNoMatchingNode(path);
                }

                nodeList.AddNode(attr);

                if (pos == path.Length)
                {
                    break;
                }
                else if (path[pos] == '|')
                {
                    pos++;
                    if (path[pos] != '@')
                    {
                        OnInvalidExpression(path);
                    }
                    pos++;
                }
                else
                {
                    OnInvalidExpression(path);
                }
            }

            return(nodeList);
        }
コード例 #9
0
        /// <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;
                }
            }
        }
コード例 #10
0
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode xmlDiffViewNode = null;

            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                var xmlElement               = (XmlElement)node;
                var xmlDiffViewElement       = new XmlDiffViewElement(xmlElement.LocalName, xmlElement.Prefix, xmlElement.NamespaceURI, this._bIgnorePrefixes);
                var enumerator1              = node.Attributes.GetEnumerator();
                XmlDiffViewAttribute refAttr = null;
                while (enumerator1.MoveNext())
                {
                    var current = (XmlAttribute)enumerator1.Current;
                    var newAttr = new XmlDiffViewAttribute(current.LocalName, current.Prefix, current.NamespaceURI, current.Value);
                    xmlDiffViewElement.InsertAttributeAfter(newAttr, refAttr);
                    refAttr = newAttr;
                }
                var             enumerator2    = node.ChildNodes.GetEnumerator();
                XmlDiffViewNode referenceChild = null;
                while (enumerator2.MoveNext())
                {
                    var newChild = this.ImportNode((XmlNode)enumerator2.Current);
                    xmlDiffViewElement.InsertChildAfter(newChild, referenceChild, false);
                    referenceChild = newChild;
                }
                xmlDiffViewNode = xmlDiffViewElement;
                break;

            case XmlNodeType.Text:
            case XmlNodeType.CDATA:
            case XmlNodeType.Comment:
                xmlDiffViewNode = new XmlDiffViewCharData(node.Value, node.NodeType);
                break;

            case XmlNodeType.EntityReference:
                xmlDiffViewNode = new XmlDiffViewER(node.Name);
                break;

            case XmlNodeType.ProcessingInstruction:
                xmlDiffViewNode = new XmlDiffViewPI(node.Name, node.Value);
                break;

            default:
                Debug.Assert(false, "Invalid node type.");
                break;
            }
            Debug.Assert(xmlDiffViewNode != null);
            return(xmlDiffViewNode);
        }
コード例 #11
0
        internal XmlDiffViewAttribute GetAttribute(string name)
        {
            XmlDiffViewAttribute curAttr = _attributes;

            while (curAttr != null)
            {
                if (curAttr._name == name && curAttr._op == XmlDiffViewOperation.Match)
                {
                    return(curAttr);
                }
                curAttr = (XmlDiffViewAttribute)curAttr._nextSibbling;
            }
            return(null);
        }
コード例 #12
0
 internal void InsertAttributeAfter(XmlDiffViewAttribute newAttr, XmlDiffViewAttribute refAttr)
 {
     Debug.Assert(newAttr != null);
     if (refAttr == null)
     {
         newAttr._nextSibbling = _attributes;
         _attributes           = newAttr;
     }
     else
     {
         newAttr._nextSibbling = refAttr._nextSibbling;
         refAttr._nextSibbling = newAttr;
     }
     newAttr._parent = this;
 }
コード例 #13
0
        /// <summary>
        /// Gets an attribute object for the specified attribute name.
        /// </summary>
        /// <param name="name">attribute name</param>
        /// <returns>an attribute object</returns>
        public XmlDiffViewAttribute GetAttribute(string name)
        {
            XmlDiffViewAttribute curAttr = this.Attributes;

            while (curAttr != null)
            {
                if (curAttr.Name == name &&
                    curAttr.Operation == XmlDiffViewOperation.Match)
                {
                    return(curAttr);
                }
                curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
            }
            return(null);
        }
コード例 #14
0
 /// <summary>
 /// Inserts an attribute object after the specified attribute object.
 /// </summary>
 /// <param name="newAttr">the attribute object to insert</param>
 /// <param name="refAttr">attribute object to insert after</param>
 public void InsertAttributeAfter(
     XmlDiffViewAttribute newAttr,
     XmlDiffViewAttribute refAttr)
 {
     Debug.Assert(newAttr != null);
     if (refAttr == null)
     {
         newAttr.NextSibbling = this.Attributes;
         this.Attributes      = newAttr;
     }
     else
     {
         newAttr.NextSibbling = refAttr.NextSibbling;
         refAttr.NextSibbling = newAttr;
     }
     newAttr.Parent = this;
 }
コード例 #15
0
        /// <summary>
        /// Creates a complete copy of the current node.
        /// </summary>
        /// <param name="deep">has child nodes</param>
        /// <returns>A copy of the current node</returns>
        internal override XmlDiffViewNode Clone(bool deep)
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement(
                this.LocalName,
                this.Prefix,
                this.NamespaceUri,
                this.ignorePrefixes);

            // attributes
            {
                XmlDiffViewAttribute curAttr    = this.Attributes;
                XmlDiffViewAttribute lastNewAtt = null;
                while (curAttr != null)
                {
                    XmlDiffViewAttribute newAttr =
                        (XmlDiffViewAttribute)curAttr.Clone(true);
                    newElement.InsertAttributeAfter(newAttr, lastNewAtt);
                    lastNewAtt = newAttr;

                    curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
                }
            }

            if (!deep)
            {
                return(newElement);
            }
            // child nodes
            {
                XmlDiffViewNode curChild     = ChildNodes;
                XmlDiffViewNode lastNewChild = null;
                while (curChild != null)
                {
                    XmlDiffViewNode newChild = curChild.Clone(true);
                    newElement.InsertChildAfter(newChild, lastNewChild, false);
                    lastNewChild = newChild;

                    curChild = curChild.NextSibbling;
                }
            }

            return(newElement);
        }
コード例 #16
0
        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 + "\"");
        }
コード例 #17
0
        /// <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 + "\"");
        }
コード例 #18
0
        internal override XmlDiffViewNode Clone(bool bDeep)
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement(_localName, _prefix, _ns, _ignorePrefixes);

            // attributes
            {
                XmlDiffViewAttribute curAttr    = _attributes;
                XmlDiffViewAttribute lastNewAtt = null;
                while (curAttr != null)
                {
                    XmlDiffViewAttribute newAttr = (XmlDiffViewAttribute)curAttr.Clone(true);
                    newElement.InsertAttributeAfter(newAttr, lastNewAtt);
                    lastNewAtt = newAttr;

                    curAttr = (XmlDiffViewAttribute)curAttr._nextSibbling;
                }
            }

            if (!bDeep)
            {
                return(newElement);
            }

            // child nodes
            {
                XmlDiffViewNode curChild     = _childNodes;
                XmlDiffViewNode lastNewChild = null;
                while (curChild != null)
                {
                    XmlDiffViewNode newChild = curChild.Clone(true);
                    newElement.InsertChildAfter(newChild, lastNewChild, false);
                    lastNewChild = newChild;

                    curChild = curChild._nextSibbling;
                }
            }

            return(newElement);
        }
コード例 #19
0
        /// <summary>
        /// Generates output data in html for a difference due
        /// to changing attribute data.
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="attr">Attribute object</param>
        /// <param name="localName">name of attribute
        /// (without the prefix)</param>
        /// <param name="prefix">xml attribute prefix</param>
        /// <param name="attributeValue">The value for the attribute.</param>
        private void DrawHtmlAttributeChange(
            XmlWriter writer,
            XmlDiffViewAttribute attr,
            string localName,
            string prefix,
            string attributeValue)
        {
            if (prefix != string.Empty)
            {
                XmlDiffView.HtmlWriteString(
                    writer,
                    this.ignorePrefixes ? XmlDiffViewOperation.Ignore : (attr.Prefix == attr.ChangeInformation.Prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                    prefix + ":");
            }

            XmlDiffView.HtmlWriteString(
                writer,
                (attr.LocalName == attr.ChangeInformation.LocalName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                this.localName);

            if (attr.AttributeValue != attr.ChangeInformation.Subset)
            {
                XmlDiffView.HtmlWriteString(writer, "=\"");
                XmlDiffView.HtmlWriteString(
                    writer,
                    XmlDiffViewOperation.Change,
                    attributeValue);
                XmlDiffView.HtmlWriteString(writer, "\"");
            }
            else
            {
                XmlDiffView.HtmlWriteString(
                    writer,
                    "=\"" + attributeValue + "\"");
            }
        }
コード例 #20
0
        private void LoadSourceChildNodes(
            XmlDiffViewParentNode parent,
            XmlReader reader,
            bool bEmptyElement)
        {
            var loadState = this._loadState;

            this._loadState.Reset();
            while (reader.MoveToNextAttribute())
            {
                XmlDiffViewAttribute newAttr;
                if (reader.Prefix == "xmlns" || reader.Prefix == string.Empty && reader.LocalName == "xmlns")
                {
                    newAttr = new XmlDiffViewAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, reader.Value);
                    if (this._bIgnoreNamespaces)
                    {
                        newAttr._op = XmlDiffViewOperation.Ignore;
                    }
                }
                else
                {
                    var str = this._bIgnoreWhitespace ? XmlDiffView.NormalizeText(reader.Value) : reader.Value;
                    newAttr = new XmlDiffViewAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, str);
                }
                ((XmlDiffViewElement)parent).InsertAttributeAfter(newAttr, this._loadState._curLastAttribute);
                this._loadState._curLastAttribute = newAttr;
            }
            if (!bEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Whitespace)
                    {
                        XmlDiffViewNode newChild = null;
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            var isEmptyElement     = reader.IsEmptyElement;
                            var xmlDiffViewElement = new XmlDiffViewElement(reader.LocalName, reader.Prefix, reader.NamespaceURI, this._bIgnorePrefixes);
                            this.LoadSourceChildNodes(xmlDiffViewElement, reader, isEmptyElement);
                            newChild = xmlDiffViewElement;
                            break;

                        case XmlNodeType.Attribute:
                            Debug.Assert(false, "We should never get to this point, attributes should be read at the beginning of thid method.");
                            break;

                        case XmlNodeType.Text:
                            newChild = new XmlDiffViewCharData(this._bIgnoreWhitespace ? XmlDiffView.NormalizeText(reader.Value) : reader.Value, XmlNodeType.Text);
                            break;

                        case XmlNodeType.CDATA:
                            newChild = new XmlDiffViewCharData(reader.Value, XmlNodeType.CDATA);
                            break;

                        case XmlNodeType.EntityReference:
                            newChild = new XmlDiffViewER(reader.Name);
                            break;

                        case XmlNodeType.ProcessingInstruction:
                            newChild = new XmlDiffViewPI(reader.Name, reader.Value);
                            if (this._bIgnorePI)
                            {
                                newChild._op = XmlDiffViewOperation.Ignore;
                                break;
                            }
                            break;

                        case XmlNodeType.Comment:
                            newChild = new XmlDiffViewCharData(reader.Value, XmlNodeType.Comment);
                            if (this._bIgnoreComments)
                            {
                                newChild._op = XmlDiffViewOperation.Ignore;
                                break;
                            }
                            break;

                        case XmlNodeType.DocumentType:
                            newChild = new XmlDiffViewDocumentType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                            if (this._bIgnoreDtd)
                            {
                                newChild._op = XmlDiffViewOperation.Ignore;
                                break;
                            }
                            break;

                        case XmlNodeType.SignificantWhitespace:
                            if (reader.XmlSpace == XmlSpace.Preserve)
                            {
                                newChild = new XmlDiffViewCharData(reader.Value, XmlNodeType.SignificantWhitespace);
                                if (this._bIgnoreWhitespace)
                                {
                                    newChild._op = XmlDiffViewOperation.Ignore;
                                    break;
                                }
                                break;
                            }
                            break;

                        case XmlNodeType.EndElement:
                            goto label_29;

                        case XmlNodeType.XmlDeclaration:
                            newChild = new XmlDiffViewXmlDeclaration(XmlDiffView.NormalizeText(reader.Value));
                            if (this._bIgnoreXmlDecl)
                            {
                                newChild._op = XmlDiffViewOperation.Ignore;
                                break;
                            }
                            break;

                        default:
                            Debug.Assert(false, "Invalid node type");
                            break;
                        }
                        parent.InsertChildAfter(newChild, this._loadState._curLastChild, true);
                        this._loadState._curLastChild = newChild;
                    }
                }
            }
label_29:
            this._loadState = loadState;
        }
コード例 #21
0
        private void DrawHtmlAttributeChange( XmlWriter writer, XmlDiffViewAttribute attr, string localName, string prefix, string value )
        {
            if ( prefix != string.Empty ) {
            XmlDiffView.HtmlWriteString( writer,
                                        _ignorePrefixes ? XmlDiffViewOperation.Ignore :
                                                          (attr._prefix == attr._changeInfo._prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                                        prefix + ":" );
            }

            XmlDiffView.HtmlWriteString( writer,
                                    (attr._localName == attr._changeInfo._localName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                                    localName );

            if ( attr._value != attr._changeInfo._value ) {
            XmlDiffView.HtmlWriteString( writer, "=\"" );
            XmlDiffView.HtmlWriteString( writer, XmlDiffViewOperation.Change, value );
            XmlDiffView.HtmlWriteString( writer, "\"" );
            }
            else {
            XmlDiffView.HtmlWriteString( writer, "=\"" + value + "\"" );
            }
        }
コード例 #22
0
        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 + "\"" );
        }
コード例 #23
0
 internal void InsertAttributeAfter( XmlDiffViewAttribute newAttr, XmlDiffViewAttribute refAttr )
 {
     Debug.Assert( newAttr != null );
     if ( refAttr == null ) {
     newAttr._nextSibbling = _attributes;
     _attributes = newAttr;
     }
     else {
     newAttr._nextSibbling = refAttr._nextSibbling;
     refAttr._nextSibbling = newAttr;
     }
     newAttr._parent = this;
 }
コード例 #24
0
        /// <summary>
        /// Add the new node or attribute 
        /// </summary>
        /// <param name="diffgramElement">node in diffgram</param>
        /// <param name="nodeTypeAttr">Whether this is an Attribute</param>
        /// <param name="sourceParent">the baseline parent node</param>
        /// <param name="currentPosition">the resulting node</param>
        private void OnAddNode(
            XmlElement diffgramElement,
            string nodeTypeAttr,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            XmlNodeType nodeType = (XmlNodeType)
                int.Parse(nodeTypeAttr);
            string name = diffgramElement.GetAttribute("name");
            string prefix = diffgramElement.GetAttribute("prefix");
            string ns = diffgramElement.GetAttribute("ns");
            string opidAttr = diffgramElement.GetAttribute("opid");
            int opid = ParseOpId(opidAttr);

            if (nodeType == XmlNodeType.Attribute)
            {
                Debug.Assert(name != string.Empty);
                XmlDiffViewAttribute newAttr = new XmlDiffViewAttribute(
                    name,
                    prefix,
                    ns,
                    diffgramElement.InnerText);
                newAttr.Operation = XmlDiffViewOperation.Add;
                newAttr.OperationId = opid;
                ((XmlDiffViewElement)
                    sourceParent).InsertAttributeAfter(newAttr, null);
            }
            else
            {
                XmlDiffViewNode newNode = null;

                switch (nodeType)
                {
                    case XmlNodeType.Element:
                        Debug.Assert(name != string.Empty);
                        newNode = new XmlDiffViewElement(
                            name,
                            prefix,
                            ns,
                            this.ignorePrefixes);
                        this.ApplyDiffgram(
                            diffgramElement,
                            (XmlDiffViewParentNode)newNode);
                        break;
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.Comment:
                        Debug.Assert(diffgramElement.InnerText != string.Empty);
                        newNode = new XmlDiffViewCharData(
                            diffgramElement.InnerText,
                            nodeType);
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        Debug.Assert(diffgramElement.InnerText != string.Empty);
                        Debug.Assert(name != string.Empty);
                        newNode = new XmlDiffViewPI(
                            name,
                            diffgramElement.InnerText);
                        break;
                    case XmlNodeType.EntityReference:
                        Debug.Assert(name != string.Empty);
                        Debug.Assert(false, "XmlDiffViewER was thought to be dead code");
                        //// newNode = new XmlDiffViewER(name);
                        break;
                    case XmlNodeType.XmlDeclaration:
                        Debug.Assert(diffgramElement.InnerText != string.Empty);
                        newNode = new XmlDiffViewXmlDeclaration(
                            diffgramElement.InnerText);
                        break;
                    case XmlNodeType.DocumentType:
                        newNode = new XmlDiffViewDocumentType(
                            diffgramElement.GetAttribute("name"),
                            diffgramElement.GetAttribute("publicId"),
                            diffgramElement.GetAttribute("systemId"),
                            diffgramElement.InnerText);
                        break;
                    default:
                        Debug.Assert(false, "Invalid node type.");
                        break;
                }
                Debug.Assert(newNode != null);
                newNode.Operation = XmlDiffViewOperation.Add;
                newNode.OperationId = opid;
                sourceParent.InsertChildAfter(newNode, currentPosition, false);
                currentPosition = newNode;
            }
        }
コード例 #25
0
 /// <summary>
 /// Inserts an attribute object after the specified attribute object.
 /// </summary>
 /// <param name="newAttr">the attribute object to insert</param>
 /// <param name="refAttr">attribute object to insert after</param>
 public void InsertAttributeAfter(
     XmlDiffViewAttribute newAttr, 
     XmlDiffViewAttribute refAttr)
 {
     Debug.Assert(newAttr != null);
     if (refAttr == null)
     {
         newAttr.NextSibbling = this.Attributes;
         this.Attributes = newAttr;
     }
     else
     {
         newAttr.NextSibbling = refAttr.NextSibbling;
         refAttr.NextSibbling = newAttr;
     }
     newAttr.Parent = this;
 }
コード例 #26
0
 public void Reset()
 {
     this._curLastChild     = null;
     this._curLastAttribute = null;
 }
コード例 #27
0
        private void OnAddNode(XmlElement diffgramElement, string nodeTypeAttr, XmlDiffViewParentNode sourceParent,
                               ref XmlDiffViewNode currentPosition)
        {
            XmlNodeType nodeType = (XmlNodeType)int.Parse(nodeTypeAttr);
            string      name     = diffgramElement.GetAttribute("name");
            string      prefix   = diffgramElement.GetAttribute("prefix");
            string      ns       = diffgramElement.GetAttribute("ns");
            string      opidAttr = diffgramElement.GetAttribute("opid");
            int         opid     = (opidAttr == string.Empty) ? 0 : int.Parse(opidAttr);

            if (nodeType == XmlNodeType.Attribute)
            {
                Debug.Assert(name != string.Empty);
                XmlDiffViewAttribute newAttr = new XmlDiffViewAttribute(name, prefix, ns, diffgramElement.InnerText);
                newAttr._op   = XmlDiffViewOperation.Add;
                newAttr._opid = opid;
                ((XmlDiffViewElement)sourceParent).InsertAttributeAfter(newAttr, null);
            }
            else
            {
                XmlDiffViewNode newNode = null;

                switch (nodeType)
                {
                case XmlNodeType.Element:
                    Debug.Assert(name != string.Empty);
                    newNode = new XmlDiffViewElement(name, prefix, ns, _bIgnorePrefixes);
                    ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)newNode);
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    newNode = new XmlDiffViewCharData(diffgramElement.InnerText, nodeType);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    Debug.Assert(name != string.Empty);
                    newNode = new XmlDiffViewPI(name, diffgramElement.InnerText);
                    break;

                case XmlNodeType.EntityReference:
                    Debug.Assert(name != string.Empty);
                    newNode = new XmlDiffViewER(name);
                    break;

                case XmlNodeType.XmlDeclaration:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    newNode = new XmlDiffViewXmlDeclaration(diffgramElement.InnerText);
                    break;

                case XmlNodeType.DocumentType:
                    newNode = new XmlDiffViewDocumentType(diffgramElement.GetAttribute("name"),
                                                          diffgramElement.GetAttribute("publicId"),
                                                          diffgramElement.GetAttribute("systemId"),
                                                          diffgramElement.InnerText);
                    break;

                default:
                    Debug.Assert(false, "Invalid node type.");
                    break;
                }
                Debug.Assert(newNode != null);
                newNode._op   = XmlDiffViewOperation.Add;
                newNode._opid = opid;
                sourceParent.InsertChildAfter(newNode, currentPosition, false);
                currentPosition = newNode;
            }
        }
コード例 #28
0
        /// <summary>
        /// Generate a new node
        /// </summary>
        /// <param name="node">node to clone</param>
        /// <returns>the new node</returns>
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode newNode = null;
            switch (node.NodeType)
            {
                case XmlNodeType.Element:
                    XmlElement el = (XmlElement)node;
                    XmlDiffViewElement newElement = new XmlDiffViewElement(
                        el.LocalName,
                        el.Prefix,
                        el.NamespaceURI,
                        this.ignorePrefixes);

                    // attributes
                    IEnumerator attributes = node.Attributes.GetEnumerator();
                    XmlDiffViewAttribute lastNewAttr = null;
                    while (attributes.MoveNext())
                    {
                        XmlAttribute at = (XmlAttribute)attributes.Current;
                        XmlDiffViewAttribute newAttr = new XmlDiffViewAttribute(
                            at.LocalName,
                            at.Prefix,
                            at.NamespaceURI,
                            at.Value);
                        newElement.InsertAttributeAfter(newAttr, lastNewAttr);
                        lastNewAttr = newAttr;
                    }

                    // children
                    IEnumerator childNodes = node.ChildNodes.GetEnumerator();
                    XmlDiffViewNode lastNewChildNode = null;
                    while (childNodes.MoveNext())
                    {
                        XmlDiffViewNode newChildNode = this.ImportNode(
                            (XmlNode)childNodes.Current);
                        newElement.InsertChildAfter(
                            newChildNode,
                            lastNewChildNode,
                            false);
                        lastNewChildNode = newChildNode;
                    }
                    newNode = newElement;
                    break;
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                    newNode = new XmlDiffViewCharData(
                        node.Value,
                        node.NodeType);
                    break;
                case XmlNodeType.ProcessingInstruction:
                    newNode = new XmlDiffViewPI(node.Name, node.Value);
                    break;
                case XmlNodeType.EntityReference:
                    Debug.Assert(false, "XmlDiffViewER was thought to be dead code");
                    //// newNode = new XmlDiffViewER(node.Name);
                    break;
                default:
                    Debug.Assert(false, "Invalid node type.");
                    break;
            }
            Debug.Assert(newNode != null);
            return newNode;
        }
コード例 #29
0
        /// <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) + "\"");
            }
        }
コード例 #30
0
        /// <summary>
        /// Recurses through the baseline document loading the
        /// contents to the XmlDiffViewDocument object and tagging
        /// the pieces to be ignored later when the data is output.
        /// </summary>
        /// <param name="parent">Parent node</param>
        /// <param name="reader">The xml data</param>
        /// <param name="emptyElement">Node has no children</param>
        private void LoadSourceChildNodes(
            XmlDiffViewParentNode parent,
            XmlReader reader,
            bool emptyElement)
        {
            LoadState savedLoadState = this.loadState;
            this.loadState.Reset();

            // load attributes
            while (reader.MoveToNextAttribute())
            {
                XmlDiffViewAttribute attr;
                if (reader.Prefix == "xmlns" ||
                    (reader.Prefix == string.Empty &&
                    reader.LocalName == "xmlns"))
                {
                    // create new DiffView attribute
                    attr = new XmlDiffViewAttribute(
                        reader.LocalName,
                        reader.Prefix,
                        reader.NamespaceURI,
                        reader.Value);
                    if (this.ignoreNamespaces)
                    {
                        // set the output operation to be performed
                        attr.Operation = XmlDiffViewOperation.Ignore;
                    }
                }
                else
                {
                    string attrValue = this.ignoreWhitespace ? NormalizeText(reader.Value) : reader.Value;
                    attr = new XmlDiffViewAttribute(
                        reader.LocalName,
                        reader.Prefix,
                        reader.NamespaceURI,
                        attrValue);
                }
                ((XmlDiffViewElement)parent).InsertAttributeAfter(
                    attr,
                    this.loadState.LastAttribute);
                this.loadState.LastAttribute = attr;
            }

            // empty element -> return, do not load chilren
            if (emptyElement)
            {
                goto End;
            }

            // load children
            while (reader.Read())
            {
                // ignore whitespaces between nodes
                if (reader.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }
                XmlDiffViewNode child = null;
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        bool emptyElementNode = reader.IsEmptyElement;
                        XmlDiffViewElement elem = new XmlDiffViewElement(
                            reader.LocalName,
                            reader.Prefix,
                            reader.NamespaceURI,
                            this.ignorePrefixes);
                        this.LoadSourceChildNodes(elem, reader, emptyElementNode);
                        child = elem;
                        break;
                    case XmlNodeType.Attribute:
                        string reason = "We should never get to this point, " +
                            "attributes should be read at the beginning of this method.";
                        Debug.Assert(false, reason);
                        break;
                    case XmlNodeType.Text:
                        child = new XmlDiffViewCharData((this.ignoreWhitespace) ? NormalizeText(reader.Value) : reader.Value, XmlNodeType.Text);
                        break;
                    case XmlNodeType.CDATA:
                        child = new XmlDiffViewCharData(reader.Value, XmlNodeType.CDATA);
                        break;
                    case XmlNodeType.EntityReference:
                        Debug.Assert(false, "XmlDiffViewER was thought to be dead code");

                        // child = new XmlDiffViewER(reader.Name);
                        break;
                    case XmlNodeType.Comment:
                        child = new XmlDiffViewCharData(reader.Value, XmlNodeType.Comment);
                        if (this.ignoreComments)
                        {
                            child.Operation = XmlDiffViewOperation.Ignore;
                        }
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        child = new XmlDiffViewPI(reader.Name, reader.Value);
                        if (this.ignorePI)
                        {
                            child.Operation = XmlDiffViewOperation.Ignore;
                        }
                        break;
                    case XmlNodeType.SignificantWhitespace:
                        if (reader.XmlSpace == XmlSpace.Preserve)
                        {
                            child = new XmlDiffViewCharData(reader.Value, XmlNodeType.SignificantWhitespace);
                            if (this.ignoreWhitespace)
                            {
                                child.Operation = XmlDiffViewOperation.Ignore;
                            }
                        }
                        break;
                    case XmlNodeType.XmlDeclaration:
                        child = new XmlDiffViewXmlDeclaration(NormalizeText(reader.Value));
                        if (this.ignoreXmlDecl)
                        {
                            child.Operation = XmlDiffViewOperation.Ignore;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        goto End;

                    case XmlNodeType.DocumentType:
                        child = new XmlDiffViewDocumentType(
                            reader.Name,
                            reader.GetAttribute("PUBLIC"),
                            reader.GetAttribute("SYSTEM"),
                            reader.Value);
                        if (this.ignoreDtd)
                        {
                            child.Operation = XmlDiffViewOperation.Ignore;
                        }
                        break;

                    default:
                        Debug.Assert(false, "Invalid node type");
                        break;
                }
                parent.InsertChildAfter(child, this.loadState.LastChild, true);
                this.loadState.LastChild = child;
            }

            End:
            this.loadState = savedLoadState;
        }
コード例 #31
0
        private void OnAddNode(
            XmlElement diffgramElement,
            string nodeTypeAttr,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            var nodeType   = (XmlNodeType)int.Parse(nodeTypeAttr);
            var attribute1 = diffgramElement.GetAttribute("name");
            var attribute2 = diffgramElement.GetAttribute("prefix");
            var attribute3 = diffgramElement.GetAttribute("ns");
            var attribute4 = diffgramElement.GetAttribute("opid");
            var num        = attribute4 == string.Empty ? 0 : int.Parse(attribute4);

            if (nodeType == XmlNodeType.Attribute)
            {
                Debug.Assert(attribute1 != string.Empty);
                var newAttr = new XmlDiffViewAttribute(attribute1, attribute2, attribute3, diffgramElement.InnerText);
                newAttr._op   = XmlDiffViewOperation.Add;
                newAttr._opid = num;
                ((XmlDiffViewElement)sourceParent).InsertAttributeAfter(newAttr, null);
            }
            else
            {
                XmlDiffViewNode newChild = null;
                switch (nodeType)
                {
                case XmlNodeType.Element:
                    Debug.Assert(attribute1 != string.Empty);
                    newChild = new XmlDiffViewElement(attribute1, attribute2, attribute3, this._bIgnorePrefixes);
                    this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)newChild);
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    newChild = new XmlDiffViewCharData(diffgramElement.InnerText, nodeType);
                    break;

                case XmlNodeType.EntityReference:
                    Debug.Assert(attribute1 != string.Empty);
                    newChild = new XmlDiffViewER(attribute1);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    Debug.Assert(attribute1 != string.Empty);
                    newChild = new XmlDiffViewPI(attribute1, diffgramElement.InnerText);
                    break;

                case XmlNodeType.DocumentType:
                    newChild = new XmlDiffViewDocumentType(diffgramElement.GetAttribute("name"), diffgramElement.GetAttribute("publicId"), diffgramElement.GetAttribute("systemId"), diffgramElement.InnerText);
                    break;

                case XmlNodeType.XmlDeclaration:
                    Debug.Assert(diffgramElement.InnerText != string.Empty);
                    newChild = new XmlDiffViewXmlDeclaration(diffgramElement.InnerText);
                    break;

                default:
                    Debug.Assert(false, "Invalid node type.");
                    break;
                }
                Debug.Assert(newChild != null);
                newChild._op   = XmlDiffViewOperation.Add;
                newChild._opid = num;
                sourceParent.InsertChildAfter(newChild, currentPosition, false);
                currentPosition = newChild;
            }
        }
コード例 #32
0
        /// <summary>
        /// Generates attributes' output data in html form
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="paneNo">Pane number, indicating
        ///  the left (baseline) or right side (actual) of the
        ///  display</param>
        private void DrawHtmlAttributes(
            XmlWriter writer,
            int paneNo)
        {
            if (this.Attributes == null)
            {
                return;
            }
            string attrIndent = string.Empty;

            if (this.Attributes.NextSibbling != null)
            {
                attrIndent = XmlDiffView.GetIndent(this.Name.Length + 2);
            }
            XmlDiffViewAttribute curAttr = this.Attributes;

            while (curAttr != null)
            {
                if (XmlDiffView.HtmlWriteToPane[(int)curAttr.Operation, paneNo])
                {
                    if (curAttr == this.Attributes)
                    {
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteRaw(attrIndent);
                    }
                    if (curAttr.Operation == XmlDiffViewOperation.Change)
                    {
                        if (paneNo == 0)
                        {
                            this.DrawHtmlAttributeChange(
                                writer,
                                curAttr,
                                curAttr.LocalName,
                                curAttr.Prefix,
                                curAttr.AttributeValue);
                        }
                        else
                        {
                            this.DrawHtmlAttributeChange(
                                writer,
                                curAttr,
                                curAttr.ChangeInformation.LocalName,
                                curAttr.ChangeInformation.Prefix,
                                curAttr.ChangeInformation.Subset);
                        }
                    }
                    else
                    {
                        this.DrawHtmlAttribute(
                            writer,
                            curAttr,
                            curAttr.Operation);
                    }
                }
                else
                {
                    XmlDiffView.HtmlWriteEmptyString(writer);
                }
                curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
                if (curAttr != null)
                {
                    XmlDiffView.HtmlBr(writer);
                }
            }
        }
コード例 #33
0
 public void Reset()
 {
     _curLastChild     = null;
     _curLastAttribute = null;
 }
コード例 #34
0
 /// <summary>
 /// Generate text output data for an unchanged attribute.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="attr">attribute object</param>
 private void DrawTextAttribute(
     TextWriter writer,
     XmlDiffViewAttribute attr)
 {
     if (this.ignorePrefixes)
     {
         if (attr.Prefix == "xmlns" || (attr.LocalName == "xmlns" && 
             attr.Prefix == string.Empty))
         {
             writer.Write(attr.Name);
             writer.Write("='" + 
                 RemoveTabsAndNewlines(attr.AttributeValue) + "'");
             return;
         }
         else if (attr.Prefix != string.Empty)
         {
             writer.Write(attr.Prefix + ":");
             writer.Write(attr.LocalName + "=\"" + 
                 RemoveTabsAndNewlines(attr.AttributeValue) + "\"");
             return;
         }
     }
     writer.Write(attr.Name + "=\"" + 
         RemoveTabsAndNewlines(attr.AttributeValue) + "\"");
 }
コード例 #35
0
        /// <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) + "\"");
            }
        }
コード例 #36
0
        /// <summary>
        /// Generates output data in html for a difference due
        /// to changing attribute data.
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="attr">Attribute object</param>
        /// <param name="localName">name of attribute 
        /// (without the prefix)</param>
        /// <param name="prefix">xml attribute prefix</param>
        /// <param name="attributeValue">The value for the attribute.</param>
        private void DrawHtmlAttributeChange(
            XmlWriter writer, 
            XmlDiffViewAttribute attr, 
            string localName, 
            string prefix, 
            string attributeValue)
        {
            if (prefix != string.Empty)
            {
                XmlDiffView.HtmlWriteString(
                    writer,
                    this.ignorePrefixes ? XmlDiffViewOperation.Ignore : (attr.Prefix == attr.ChangeInformation.Prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                    prefix + ":");
            }

            XmlDiffView.HtmlWriteString(
                writer,
                (attr.LocalName == attr.ChangeInformation.LocalName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                this.localName);

            if (attr.AttributeValue != attr.ChangeInformation.Subset)
            {
                XmlDiffView.HtmlWriteString(writer, "=\"");
                XmlDiffView.HtmlWriteString(
                    writer, 
                    XmlDiffViewOperation.Change, 
                    attributeValue);
                XmlDiffView.HtmlWriteString(writer, "\"");
            }
            else
            {
                XmlDiffView.HtmlWriteString(
                    writer, 
                    "=\"" + attributeValue + "\"");
            }
        }
コード例 #37
0
 /// <summary>
 /// Clear the references the last 
 /// child node and attribute processed.
 /// </summary>
 public void Reset()
 {
     this.lastChild = null;
     this.lastAttribute = null;
 }
コード例 #38
0
        /// <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 + "\"");
        }
コード例 #39
0
        private void LoadSourceChildNodes(XmlDiffViewParentNode parent, XmlReader reader, bool bEmptyElement)
        {
            LoadState savedLoadState = _loadState;

            _loadState.Reset();

            // load attributes
            while (reader.MoveToNextAttribute())
            {
                XmlDiffViewAttribute attr;
                if (reader.Prefix == "xmlns" ||
                    (reader.Prefix == string.Empty && reader.LocalName == "xmlns"))
                {
                    attr = new XmlDiffViewAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, reader.Value);
                    if (_bIgnoreNamespaces)
                    {
                        attr._op = XmlDiffViewOperation.Ignore;
                    }
                }
                else
                {
                    string attrValue = _bIgnoreWhitespace ? NormalizeText(reader.Value) : reader.Value;
                    attr = new XmlDiffViewAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, attrValue);
                }
                ((XmlDiffViewElement)parent).InsertAttributeAfter(attr, _loadState._curLastAttribute);
                _loadState._curLastAttribute = attr;
            }

            // empty element -> return, do not load chilren
            if (bEmptyElement)
            {
                goto End;
            }

            // load children
            while (reader.Read())
            {
                // ignore whitespaces between nodes
                if (reader.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }

                XmlDiffViewNode child = null;
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    bool bEmptyEl           = reader.IsEmptyElement;
                    XmlDiffViewElement elem = new XmlDiffViewElement(reader.LocalName, reader.Prefix, reader.NamespaceURI, _bIgnorePrefixes);
                    LoadSourceChildNodes(elem, reader, bEmptyEl);
                    child = elem;
                    break;

                case XmlNodeType.Attribute:
                    Debug.Assert(false, "We should never get to this point, attributes should be read at the beginning of thid method.");
                    break;

                case XmlNodeType.Text:
                    child = new XmlDiffViewCharData((_bIgnoreWhitespace) ? NormalizeText(reader.Value) : reader.Value, XmlNodeType.Text);
                    break;

                case XmlNodeType.CDATA:
                    child = new XmlDiffViewCharData(reader.Value, XmlNodeType.CDATA);
                    break;

                case XmlNodeType.EntityReference:
                    child = new XmlDiffViewER(reader.Name);
                    break;

                case XmlNodeType.Comment:
                    child = new XmlDiffViewCharData(reader.Value, XmlNodeType.Comment);
                    if (_bIgnoreComments)
                    {
                        child._op = XmlDiffViewOperation.Ignore;
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    child = new XmlDiffViewPI(reader.Name, reader.Value);
                    if (_bIgnorePI)
                    {
                        child._op = XmlDiffViewOperation.Ignore;
                    }
                    break;

                case XmlNodeType.SignificantWhitespace:
                    if (reader.XmlSpace == XmlSpace.Preserve)
                    {
                        child = new XmlDiffViewCharData(reader.Value, XmlNodeType.SignificantWhitespace);
                        if (_bIgnoreWhitespace)
                        {
                            child._op = XmlDiffViewOperation.Ignore;
                        }
                    }
                    break;

                case XmlNodeType.XmlDeclaration:
                    child = new XmlDiffViewXmlDeclaration(NormalizeText(reader.Value));
                    if (_bIgnoreXmlDecl)
                    {
                        child._op = XmlDiffViewOperation.Ignore;
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto End;

                case XmlNodeType.DocumentType:
                    child = new XmlDiffViewDocumentType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                    if (_bIgnoreDtd)
                    {
                        child._op = XmlDiffViewOperation.Ignore;
                    }
                    break;

                default:
                    Debug.Assert(false, "Invalid node type");
                    break;
                }
                parent.InsertChildAfter(child, _loadState._curLastChild, true);
                _loadState._curLastChild = child;
            }

End:
            _loadState = savedLoadState;
        }