示例#1
0
 private void InsertTopLevelAttributeAsText(XmlDiffNode parent, XmlDiffCharacterData newChild)
 {
     if (parent.LastChild != null && (parent.LastChild.NodeType == XmlDiffNodeType.Text || parent.LastChild.NodeType == XmlDiffNodeType.WS))
     {
         ((XmlDiffCharacterData)parent.LastChild).Value = ((XmlDiffCharacterData)parent.LastChild).Value + " " + newChild.Value;
     }
     else
     {
         parent.InsertChildAfter(parent.LastChild, newChild);
     }
 }
示例#2
0
 private void LoadTextNode(XmlDiffNode parent, string text, PositionInfo pInfo, XmlDiffNodeType nt)
 {
     if (!this.IgnoreEmptyTextNodes || !String.IsNullOrEmpty(text))
     {
         XmlDiffCharacterData textNode = new XmlDiffCharacterData(text, nt, this.NormalizeNewline)
         {
             LineNumber   = pInfo.LineNumber,
             LinePosition = pInfo.LinePosition
         };
         InsertChild(parent, textNode);
     }
 }
示例#3
0
        private NodePosition CompareTextLikeNodes(XmlDiffCharacterData t1, XmlDiffCharacterData t2)
        {
            Debug.Assert(t1 != null);
            Debug.Assert(t2 != null);

            int nCompare = CompareText(t2.Value, t1.Value);

            if (nCompare >= 0)
            {
                return(NodePosition.After);
            }
            else
            {
                return(NodePosition.Before);
            }
        }
示例#4
0
        /// <summary>
        /// Combines multiple adjacent text nodes into a single node.
        /// Sometimes the binary reader/writer will break text nodes in multiple
        /// nodes; i.e., if the user calls
        /// <code>writer.WriteString(&quot;foo&quot;); writer.WriteString(&quot;bar&quot;)</code>
        /// on the writer and then iterate calling reader.Read() on the document, the binary
        /// reader will report two text nodes (&quot;foo&quot;, &quot;bar&quot;), while the
        /// other readers will report a single text node (&quot;node1&quot;)  notice that
        /// this is not a problem; calling ReadString, or Read[Element]ContentAsString in
        /// all readers will return &quot;node1&quot;.
        /// </summary>
        /// <param name="node">the node to be normalized. Any siblings of
        /// type XmlDiffCharacterData will be removed, with their values appended
        /// to the value of this node</param>
        private void DoConcatenateAdjacentTextNodes(XmlDiffCharacterData node)
        {
            if (node.NextSibling == null)
            {
                return;
            }
            if (!(node.NextSibling is XmlDiffCharacterData))
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(node.Value);
            XmlDiffCharacterData nextNode = (node.NextSibling as XmlDiffCharacterData);

            while (nextNode != null)
            {
                sb.Append(nextNode.Value);
                XmlDiffCharacterData curNextNode = nextNode;
                nextNode = (nextNode.NextSibling as XmlDiffCharacterData);
                curNextNode.ParentNode.DeleteChild(curNextNode);
            }
            node.Value = sb.ToString();
        }
示例#5
0
        // This function compares the two nodes passed to it, depending upon the options set by the user.
        private DiffType CompareNodes(XmlDiffNode sourceNode, XmlDiffNode targetNode)
        {
            if (sourceNode.NodeType != targetNode.NodeType)
            {
                return(DiffType.NodeType);
            }
            switch (sourceNode.NodeType)
            {
            case XmlDiffNodeType.Element:
                XmlDiffElement sourceElem = sourceNode as XmlDiffElement;
                XmlDiffElement targetElem = targetNode as XmlDiffElement;
                Debug.Assert(sourceElem != null);
                Debug.Assert(targetElem != null);
                if (!IgnoreNS)
                {
                    if (sourceElem.NamespaceURI != targetElem.NamespaceURI)
                    {
                        return(DiffType.NS);
                    }
                }
                if (!IgnorePrefix)
                {
                    if (sourceElem.Prefix != targetElem.Prefix)
                    {
                        return(DiffType.Prefix);
                    }
                }

                if (sourceElem.LocalName != targetElem.LocalName)
                {
                    return(DiffType.Element);
                }
                if (!IgnoreEmptyElement)
                {
                    if ((sourceElem is XmlDiffEmptyElement) != (targetElem is XmlDiffEmptyElement))
                    {
                        return(DiffType.Element);
                    }
                }
                if (!CompareAttributes(sourceElem, targetElem))
                {
                    return(DiffType.Attribute);
                }
                break;

            case XmlDiffNodeType.Text:
            case XmlDiffNodeType.Comment:
            case XmlDiffNodeType.WS:
                XmlDiffCharacterData sourceText = sourceNode as XmlDiffCharacterData;
                XmlDiffCharacterData targetText = targetNode as XmlDiffCharacterData;
                Debug.Assert(sourceText != null);
                Debug.Assert(targetText != null);

                if (ConcatenateAdjacentTextNodes)
                {
                    DoConcatenateAdjacentTextNodes(sourceText);
                    DoConcatenateAdjacentTextNodes(targetText);
                }

                if (IgnoreWhitespace)
                {
                    if (sourceText.Value.Trim() == targetText.Value.Trim())
                    {
                        return(DiffType.Success);
                    }
                }
                else
                {
                    if (sourceText.Value == targetText.Value)
                    {
                        return(DiffType.Success);
                    }
                }
                if (sourceText.NodeType == XmlDiffNodeType.Text || sourceText.NodeType == XmlDiffNodeType.WS)     //should ws nodes also as text nodes???
                {
                    return(DiffType.Text);
                }
                else if (sourceText.NodeType == XmlDiffNodeType.Comment)
                {
                    return(DiffType.Comment);
                }
                else if (sourceText.NodeType == XmlDiffNodeType.CData)
                {
                    return(DiffType.CData);
                }
                else
                {
                    return(DiffType.None);
                }

            case XmlDiffNodeType.PI:
                XmlDiffProcessingInstruction sourcePI = sourceNode as XmlDiffProcessingInstruction;
                XmlDiffProcessingInstruction targetPI = targetNode as XmlDiffProcessingInstruction;
                Debug.Assert(sourcePI != null);
                Debug.Assert(targetPI != null);
                if (sourcePI.Name != targetPI.Name || sourcePI.Value != targetPI.Value)
                {
                    return(DiffType.PI);
                }
                break;

            default:
                break;
            }

            return(DiffType.Success);
        }