Example #1
0
 internal void LoadChildNodes(XmlDiffParentNode parent, XmlNode parentDomNode)
 {
         var curLastChild = this._curLastChild;
   this._curLastChild = (XmlDiffNode) null;
         var attributes = (XmlNamedNodeMap) parentDomNode.Attributes;
   if (attributes != null && attributes.Count > 0)
   {
     foreach (XmlAttribute xmlAttribute in attributes)
     {
       if (xmlAttribute.Prefix == "xmlns")
       {
         if (!this._XmlDiff.IgnoreNamespaces)
         {
                         var xmlDiffNamespace = new XmlDiffNamespace(xmlAttribute.LocalName, xmlAttribute.Value);
           xmlDiffNamespace.ComputeHashValue(this._xmlHash);
           this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffNamespace);
         }
       }
       else if (xmlAttribute.Prefix == string.Empty && xmlAttribute.LocalName == "xmlns")
       {
         if (!this._XmlDiff.IgnoreNamespaces)
         {
                         var xmlDiffNamespace = new XmlDiffNamespace(string.Empty, xmlAttribute.Value);
           xmlDiffNamespace.ComputeHashValue(this._xmlHash);
           this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffNamespace);
         }
       }
       else
       {
         var str = this._XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(xmlAttribute.Value) : xmlAttribute.Value;
                     var xmlDiffAttribute = new XmlDiffAttribute(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI, str);
         xmlDiffAttribute.ComputeHashValue(this._xmlHash);
         this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffAttribute);
       }
     }
   }
         var childNodes = parentDomNode.ChildNodes;
   if (childNodes.Count != 0)
   {
     var childPosition = 0;
             var enumerator = childNodes.GetEnumerator();
     while (enumerator.MoveNext())
     {
       if (((XmlNode) enumerator.Current).NodeType != XmlNodeType.Whitespace)
       {
                     var newChild = this.LoadNode((XmlNode) enumerator.Current, ref childPosition);
         if (newChild != null)
           this.InsertChild(parent, newChild);
       }
     }
   }
   this._curLastChild = curLastChild;
 }
Example #2
0
        // Loads child nodes of the 'parent' node
        internal void LoadChildNodes(XmlDiffParentNode parent, XmlNode parentDomNode)
        {
            XmlDiffNode savedLastChild = _curLastChild;

            _curLastChild = null;

            // load attributes & namespace nodes
            XmlNamedNodeMap attribs = parentDomNode.Attributes;

            if (attribs != null && attribs.Count > 0)
            {
                IEnumerator attrEnum = attribs.GetEnumerator();
                while (attrEnum.MoveNext())
                {
                    XmlAttribute attr = (XmlAttribute)attrEnum.Current;
                    if (attr.Prefix == "xmlns")
                    {
                        if (!_XmlDiff.IgnoreNamespaces)
                        {
                            XmlDiffNamespace nsNode = new XmlDiffNamespace(attr.LocalName, attr.Value);
                            nsNode.ComputeHashValue(_xmlHash);
                            InsertAttributeOrNamespace((XmlDiffElement)parent, nsNode);
                        }
                    }
                    else if (attr.Prefix == string.Empty && attr.LocalName == "xmlns")
                    {
                        if (!_XmlDiff.IgnoreNamespaces)
                        {
                            XmlDiffNamespace nsNode = new XmlDiffNamespace(string.Empty, attr.Value);
                            nsNode.ComputeHashValue(_xmlHash);
                            InsertAttributeOrNamespace((XmlDiffElement)parent, nsNode);
                        }
                    }
                    else
                    {
                        string           attrValue = _XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(attr.Value) : attr.Value;
                        XmlDiffAttribute newAttr   = new XmlDiffAttribute(attr.LocalName, attr.Prefix, attr.NamespaceURI, attrValue);
                        newAttr.ComputeHashValue(_xmlHash);
                        InsertAttributeOrNamespace((XmlDiffElement)parent, newAttr);
                    }
                }
            }

            // load children
            XmlNodeList children = parentDomNode.ChildNodes;

            if (children.Count == 0)
            {
                goto End;
            }

            int         childPosition = 0;
            IEnumerator childEnum     = children.GetEnumerator();

            while (childEnum.MoveNext())
            {
                XmlNode node = (XmlNode)childEnum.Current;

                // ignore whitespaces between nodes
                if (node.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }

                XmlDiffNode newDiffNode = LoadNode((XmlNode)childEnum.Current, ref childPosition);
                if (newDiffNode != null)
                {
                    InsertChild(parent, newDiffNode);
                }
            }

End:
            _curLastChild = savedLastChild;
        }
Example #3
0
        internal XmlDiffNode LoadNode(XmlNode node, ref int childPosition)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                XmlDiffElement elem = new XmlDiffElement(++childPosition, node.LocalName, node.Prefix, node.NamespaceURI);
                LoadChildNodes(elem, node);
                elem.ComputeHashValue(_xmlHash);
                return(elem);

            case XmlNodeType.Attribute:
                Debug.Assert(false, "Attributes cannot be loaded by this method.");
                return(null);

            case XmlNodeType.Text:
                string          textValue = (_XmlDiff.IgnoreWhitespace) ? XmlDiff.NormalizeText(node.Value) : node.Value;
                XmlDiffCharData text      = new XmlDiffCharData(++childPosition, textValue, XmlDiffNodeType.Text);
                text.ComputeHashValue(_xmlHash);
                return(text);

            case XmlNodeType.CDATA:
                XmlDiffCharData cdata = new XmlDiffCharData(++childPosition, node.Value, XmlDiffNodeType.CDATA);
                cdata.ComputeHashValue(_xmlHash);
                return(cdata);

            case XmlNodeType.EntityReference:
                XmlDiffER er = new XmlDiffER(++childPosition, node.Name);
                er.ComputeHashValue(_xmlHash);
                return(er);

            case XmlNodeType.Comment:
                ++childPosition;
                if (_XmlDiff.IgnoreComments)
                {
                    return(null);
                }

                XmlDiffCharData comment = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.Comment);
                comment.ComputeHashValue(_xmlHash);
                return(comment);

            case XmlNodeType.ProcessingInstruction:
                ++childPosition;
                if (_XmlDiff.IgnorePI)
                {
                    return(null);
                }

                XmlDiffPI pi = new XmlDiffPI(childPosition, node.Name, node.Value);
                pi.ComputeHashValue(_xmlHash);
                return(pi);

            case XmlNodeType.SignificantWhitespace:
                ++childPosition;
                if (_XmlDiff.IgnoreWhitespace)
                {
                    return(null);
                }
                XmlDiffCharData ws = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.SignificantWhitespace);
                ws.ComputeHashValue(_xmlHash);
                return(ws);

            case XmlNodeType.XmlDeclaration:
                ++childPosition;
                if (_XmlDiff.IgnoreXmlDecl)
                {
                    return(null);
                }
                XmlDiffXmlDeclaration xmlDecl = new XmlDiffXmlDeclaration(childPosition, XmlDiff.NormalizeXmlDeclaration(node.Value));
                xmlDecl.ComputeHashValue(_xmlHash);
                return(xmlDecl);

            case XmlNodeType.EndElement:
                return(null);

            case XmlNodeType.DocumentType:
                childPosition++;
                if (_XmlDiff.IgnoreDtd)
                {
                    return(null);
                }

                XmlDocumentType     docType     = (XmlDocumentType)node;
                XmlDiffDocumentType diffDocType = new XmlDiffDocumentType(childPosition, docType.Name, docType.PublicId, docType.SystemId, docType.InternalSubset);
                diffDocType.ComputeHashValue(_xmlHash);
                return(diffDocType);

            default:
                Debug.Assert(false);
                return(null);
            }
        }
Example #4
0
        // Loads child nodes of the 'parent' node
        internal void LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, bool bEmptyElement)
        {
            XmlDiffNode savedLastChild = _curLastChild;

            _curLastChild = null;

            // load attributes & namespace nodes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Prefix == "xmlns")
                {
                    if (!_XmlDiff.IgnoreNamespaces)
                    {
                        XmlDiffNamespace nsNode = new XmlDiffNamespace(reader.LocalName, reader.Value);
                        nsNode.ComputeHashValue(_xmlHash);
                        InsertAttributeOrNamespace((XmlDiffElement)parent, nsNode);
                    }
                }
                else if (reader.Prefix == string.Empty && reader.LocalName == "xmlns")
                {
                    if (!_XmlDiff.IgnoreNamespaces)
                    {
                        XmlDiffNamespace nsNode = new XmlDiffNamespace(string.Empty, reader.Value);
                        nsNode.ComputeHashValue(_xmlHash);
                        InsertAttributeOrNamespace((XmlDiffElement)parent, nsNode);
                    }
                }
                else
                {
                    string           attrValue = _XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(reader.Value) : reader.Value;
                    XmlDiffAttribute attr      = new XmlDiffAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, attrValue);
                    attr.ComputeHashValue(_xmlHash);
                    InsertAttributeOrNamespace((XmlDiffElement)parent, attr);
                }
            }

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

            int childPosition = 0;

            // load children
            if (!reader.Read())
            {
                goto End;
            }

            do
            {
                // ignore whitespaces between nodes
                if (reader.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    bool           bEmptyEl = reader.IsEmptyElement;
                    XmlDiffElement elem     = new XmlDiffElement(++childPosition, reader.LocalName, reader.Prefix, reader.NamespaceURI);

                    LoadChildNodes(elem, reader, bEmptyEl);

                    elem.ComputeHashValue(_xmlHash);
                    InsertChild(parent, 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:
                {
                    string          textValue    = (_XmlDiff.IgnoreWhitespace) ? XmlDiff.NormalizeText(reader.Value) : reader.Value;
                    XmlDiffCharData charDataNode = new XmlDiffCharData(++childPosition, textValue, XmlDiffNodeType.Text);
                    charDataNode.ComputeHashValue(_xmlHash);
                    InsertChild(parent, charDataNode);
                    break;
                }

                case XmlNodeType.CDATA:
                {
                    XmlDiffCharData charDataNode = new XmlDiffCharData(++childPosition, reader.Value, XmlDiffNodeType.CDATA);
                    charDataNode.ComputeHashValue(_xmlHash);
                    InsertChild(parent, charDataNode);
                    break;
                }

                case XmlNodeType.EntityReference:
                {
                    XmlDiffER er = new XmlDiffER(++childPosition, reader.Name);
                    er.ComputeHashValue(_xmlHash);
                    InsertChild(parent, er);
                    break;
                }

                case XmlNodeType.Comment:
                {
                    ++childPosition;
                    if (!_XmlDiff.IgnoreComments)
                    {
                        XmlDiffCharData charDataNode = new XmlDiffCharData(childPosition, reader.Value, XmlDiffNodeType.Comment);
                        charDataNode.ComputeHashValue(_xmlHash);
                        InsertChild(parent, charDataNode);
                    }
                    break;
                }

                case XmlNodeType.ProcessingInstruction:
                {
                    ++childPosition;
                    if (!_XmlDiff.IgnorePI)
                    {
                        XmlDiffPI pi = new XmlDiffPI(childPosition, reader.Name, reader.Value);
                        pi.ComputeHashValue(_xmlHash);
                        InsertChild(parent, pi);
                    }
                    break;
                }

                case XmlNodeType.SignificantWhitespace:
                {
                    if (reader.XmlSpace == XmlSpace.Preserve)
                    {
                        ++childPosition;
                        if (!_XmlDiff.IgnoreWhitespace)
                        {
                            XmlDiffCharData charDataNode = new XmlDiffCharData(childPosition, reader.Value, XmlDiffNodeType.SignificantWhitespace);
                            charDataNode.ComputeHashValue(_xmlHash);
                            InsertChild(parent, charDataNode);
                        }
                    }
                    break;
                }

                case XmlNodeType.XmlDeclaration:
                {
                    ++childPosition;
                    if (!_XmlDiff.IgnoreXmlDecl)
                    {
                        XmlDiffXmlDeclaration xmlDecl = new XmlDiffXmlDeclaration(childPosition, XmlDiff.NormalizeXmlDeclaration(reader.Value));
                        xmlDecl.ComputeHashValue(_xmlHash);
                        InsertChild(parent, xmlDecl);
                    }
                    break;
                }

                case XmlNodeType.EndElement:
                    goto End;

                case XmlNodeType.DocumentType:
                    childPosition++;
                    if (!_XmlDiff.IgnoreDtd)
                    {
                        XmlDiffDocumentType docType = new XmlDiffDocumentType(childPosition,
                                                                              reader.Name,
                                                                              reader.GetAttribute("PUBLIC"),
                                                                              reader.GetAttribute("SYSTEM"),
                                                                              reader.Value);
                        docType.ComputeHashValue(_xmlHash);
                        InsertChild(parent, docType);
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            } while (reader.Read());

End:
            _curLastChild = savedLastChild;
        }
Example #5
0
 internal static string NormalizeXmlDeclaration(string value)
 {
     value = value.Replace('\'', '"');
     return(XmlDiff.NormalizeText(value));
 }
Example #6
0
        private ulong ComputeHashXmlNode(XmlNode node)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
            {
                XmlElement    el = (XmlElement)node;
                HashAlgorithm ha = new HashAlgorithm();

                HashElement(ha, el.LocalName, el.Prefix, el.NamespaceURI);
                ComputeHashXmlChildren(ha, el);

                return(ha.Hash);
            }

            case XmlNodeType.Attribute:
                // attributes are hashed in ComputeHashXmlChildren;
                Debug.Assert(false);
                return(0);

            case XmlNodeType.Whitespace:
                return(0);

            case XmlNodeType.SignificantWhitespace:
                if (!_bIgnoreWhitespace)
                {
                    goto case XmlNodeType.Text;
                }
                return(0);

            case XmlNodeType.Comment:
                if (!_bIgnoreComments)
                {
                    return(HashCharacterNode(XmlNodeType.Comment, ((XmlCharacterData)node).Value));
                }
                return(0);

            case XmlNodeType.Text:
            {
                XmlCharacterData cd = (XmlCharacterData)node;
                if (_bIgnoreWhitespace)
                {
                    return(HashCharacterNode(cd.NodeType, XmlDiff.NormalizeText(cd.Value)));
                }
                else
                {
                    return(HashCharacterNode(cd.NodeType, cd.Value));
                }
            }

            case XmlNodeType.CDATA:
            {
                XmlCharacterData cd = (XmlCharacterData)node;
                return(HashCharacterNode(cd.NodeType, cd.Value));
            }

            case XmlNodeType.ProcessingInstruction:
            {
                if (_bIgnorePI)
                {
                    return(0);
                }

                XmlProcessingInstruction pi = (XmlProcessingInstruction)node;
                return(HashPI(pi.Target, pi.Value));
            }

            case XmlNodeType.EntityReference:
            {
                XmlEntityReference er = (XmlEntityReference)node;
                return(HashER(er.Name));
            }

            case XmlNodeType.XmlDeclaration:
            {
                if (_bIgnoreXmlDecl)
                {
                    return(0);
                }
                XmlDeclaration decl = (XmlDeclaration)node;
                return(HashXmlDeclaration(XmlDiff.NormalizeXmlDeclaration(decl.Value)));
            }

            case XmlNodeType.DocumentType:
            {
                if (_bIgnoreDtd)
                {
                    return(0);
                }
                XmlDocumentType docType = (XmlDocumentType)node;
                return(HashDocumentType(docType.Name, docType.PublicId, docType.SystemId, docType.InternalSubset));
            }

            case XmlNodeType.DocumentFragment:
                return(0);

            default:
                Debug.Assert(false);
                return(0);
            }
        }
Example #7
0
        private void ComputeHashXmlChildren(HashAlgorithm ha, XmlNode parent)
        {
            XmlElement el = parent as XmlElement;

            if (el != null)
            {
                ulong attrHashSum            = 0;
                int   attrsCount             = 0;
                XmlAttributeCollection attrs = ((XmlElement)parent).Attributes;
                for (int i = 0; i < attrs.Count; i++)
                {
                    XmlAttribute attr = (XmlAttribute)attrs.Item(i);

                    ulong hashValue = 0;

                    // default namespace def
                    if (attr.LocalName == "xmlns" && attr.Prefix == string.Empty)
                    {
                        if (_bIgnoreNamespaces)
                        {
                            continue;
                        }
                        hashValue = HashNamespace(string.Empty, attr.Value);
                    }
                    // namespace def
                    else if (attr.Prefix == "xmlns")
                    {
                        if (_bIgnoreNamespaces)
                        {
                            continue;
                        }
                        hashValue = HashNamespace(attr.LocalName, attr.Value);
                    }
                    // attribute
                    else
                    {
                        if (_bIgnoreWhitespace)
                        {
                            hashValue = HashAttribute(attr.LocalName, attr.Prefix, attr.NamespaceURI, XmlDiff.NormalizeText(attr.Value));
                        }
                        else
                        {
                            hashValue = HashAttribute(attr.LocalName, attr.Prefix, attr.NamespaceURI, attr.Value);
                        }
                    }

                    Debug.Assert(hashValue != 0);

                    attrsCount++;
                    attrHashSum += hashValue;
                }

                if (attrsCount != 0)
                {
                    ha.AddULong(attrHashSum);
                    ha.AddInt(attrsCount);
                }
            }

            int childrenCount = 0;

            if (_bIgnoreChildOrder)
            {
                ulong   totalHashSum = 0;
                XmlNode curChild     = parent.FirstChild;
                while (curChild != null)
                {
                    ulong hashValue = ComputeHashXmlNode(curChild);
                    if (hashValue != 0)
                    {
                        totalHashSum += hashValue;
                        childrenCount++;
                    }
                    curChild = curChild.NextSibling;
                }
                ha.AddULong(totalHashSum);
            }
            else
            {
                XmlNode curChild = parent.FirstChild;
                while (curChild != null)
                {
                    ulong hashValue = ComputeHashXmlNode(curChild);
                    if (hashValue != 0)
                    {
                        ha.AddULong(hashValue);
                        childrenCount++;
                    }
                    curChild = curChild.NextSibling;
                }
            }
            if (childrenCount != 0)
            {
                ha.AddInt(childrenCount);
            }
        }
Example #8
0
        private ulong ComputeHashXmlNode(XmlNode node)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                var xmlElement = (XmlElement)node;
                var ha         = new HashAlgorithm();
                this.HashElement(ha, xmlElement.LocalName, xmlElement.Prefix, xmlElement.NamespaceURI);
                this.ComputeHashXmlChildren(ha, (XmlNode)xmlElement);
                return(ha.Hash);

            case XmlNodeType.Attribute:
                return(0);

            case XmlNodeType.Text:
                var xmlCharacterData1 = (XmlCharacterData)node;
                return(this._bIgnoreWhitespace ? this.HashCharacterNode(xmlCharacterData1.NodeType, XmlDiff.NormalizeText(xmlCharacterData1.Value)) : this.HashCharacterNode(xmlCharacterData1.NodeType, xmlCharacterData1.Value));

            case XmlNodeType.CDATA:
                var xmlCharacterData2 = (XmlCharacterData)node;
                return(this.HashCharacterNode(xmlCharacterData2.NodeType, xmlCharacterData2.Value));

            case XmlNodeType.EntityReference:
                return(this.HashER(node.Name));

            case XmlNodeType.ProcessingInstruction:
                if (this._bIgnorePI)
                {
                    return(0);
                }
                var processingInstruction = (XmlProcessingInstruction)node;
                return(this.HashPI(processingInstruction.Target, processingInstruction.Value));

            case XmlNodeType.Comment:
                return(!this._bIgnoreComments ? this.HashCharacterNode(XmlNodeType.Comment, node.Value) : 0UL);

            case XmlNodeType.DocumentType:
                if (this._bIgnoreDtd)
                {
                    return(0);
                }
                var xmlDocumentType = (XmlDocumentType)node;
                return(this.HashDocumentType(xmlDocumentType.Name, xmlDocumentType.PublicId, xmlDocumentType.SystemId, xmlDocumentType.InternalSubset));

            case XmlNodeType.DocumentFragment:
                return(0);

            case XmlNodeType.Whitespace:
                return(0);

            case XmlNodeType.SignificantWhitespace:
                if (this._bIgnoreWhitespace)
                {
                    return(0);
                }
                goto case XmlNodeType.Text;

            case XmlNodeType.XmlDeclaration:
                return(this._bIgnoreXmlDecl ? 0UL : this.HashXmlDeclaration(XmlDiff.NormalizeXmlDeclaration(node.Value)));

            default:
                return(0);
            }
        }
Example #9
0
        private void ComputeHashXmlChildren(HashAlgorithm ha, XmlNode parent)
        {
            if (parent is XmlElement)
            {
                ulong u          = 0;
                var   i          = 0;
                var   attributes = parent.Attributes;
                for (var index = 0; index < attributes.Count; ++index)
                {
                    var   xmlAttribute = (XmlAttribute)attributes.Item(index);
                    ulong num;
                    if (xmlAttribute.LocalName == "xmlns" && xmlAttribute.Prefix == string.Empty)
                    {
                        if (!this._bIgnoreNamespaces)
                        {
                            num = this.HashNamespace(string.Empty, xmlAttribute.Value);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (xmlAttribute.Prefix == "xmlns")
                    {
                        if (!this._bIgnoreNamespaces)
                        {
                            num = this.HashNamespace(xmlAttribute.LocalName, xmlAttribute.Value);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        num = !this._bIgnoreWhitespace ? this.HashAttribute(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI, xmlAttribute.Value) : this.HashAttribute(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI, XmlDiff.NormalizeText(xmlAttribute.Value));
                    }
                    ++i;
                    u += num;
                }
                if (i != 0)
                {
                    ha.AddULong(u);
                    ha.AddInt(i);
                }
            }
            var i1 = 0;

            if (this._bIgnoreChildOrder)
            {
                ulong u = 0;
                for (var node = parent.FirstChild; node != null; node = node.NextSibling)
                {
                    var hashXmlNode = this.ComputeHashXmlNode(node);
                    if (hashXmlNode != 0UL)
                    {
                        u += hashXmlNode;
                        ++i1;
                    }
                }
                ha.AddULong(u);
            }
            else
            {
                for (var node = parent.FirstChild; node != null; node = node.NextSibling)
                {
                    var hashXmlNode = this.ComputeHashXmlNode(node);
                    if (hashXmlNode != 0UL)
                    {
                        ha.AddULong(hashXmlNode);
                        ++i1;
                    }
                }
            }
            if (i1 == 0)
            {
                return;
            }
            ha.AddInt(i1);
        }
Example #10
0
    internal void LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, bool bEmptyElement)
    {
            var curLastChild = this._curLastChild;
      this._curLastChild = (XmlDiffNode) null;
      while (reader.MoveToNextAttribute())
      {
        if (reader.Prefix == "xmlns")
        {
          if (!this._XmlDiff.IgnoreNamespaces)
          {
                        var xmlDiffNamespace = new XmlDiffNamespace(reader.LocalName, reader.Value);
            xmlDiffNamespace.ComputeHashValue(this._xmlHash);
            this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffNamespace);
          }
        }
        else if (reader.Prefix == string.Empty && reader.LocalName == "xmlns")
        {
          if (!this._XmlDiff.IgnoreNamespaces)
          {
                        var xmlDiffNamespace = new XmlDiffNamespace(string.Empty, reader.Value);
            xmlDiffNamespace.ComputeHashValue(this._xmlHash);
            this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffNamespace);
          }
        }
        else
        {
          var str = this._XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(reader.Value) : reader.Value;
                    var xmlDiffAttribute = new XmlDiffAttribute(reader.LocalName, reader.Prefix, reader.NamespaceURI, str);
          xmlDiffAttribute.ComputeHashValue(this._xmlHash);
          this.InsertAttributeOrNamespace((XmlDiffElement) parent, (XmlDiffAttributeOrNamespace) xmlDiffAttribute);
        }
      }
      if (!bEmptyElement)
      {
        var position = 0;
        if (reader.Read())
        {
          do
          {
            if (reader.NodeType != XmlNodeType.Whitespace)
            {
              switch (reader.NodeType)
              {
                case XmlNodeType.Element:
                  var isEmptyElement = reader.IsEmptyElement;
                                    var xmlDiffElement = new XmlDiffElement(++position, reader.LocalName, reader.Prefix, reader.NamespaceURI);
                  this.LoadChildNodes((XmlDiffParentNode) xmlDiffElement, reader, isEmptyElement);
                  xmlDiffElement.ComputeHashValue(this._xmlHash);
                  this.InsertChild(parent, (XmlDiffNode) xmlDiffElement);
                  break;
                case XmlNodeType.Text:
                  var str = this._XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(reader.Value) : reader.Value;
                                    var xmlDiffCharData1 = new XmlDiffCharData(++position, str, XmlDiffNodeType.Text);
                  xmlDiffCharData1.ComputeHashValue(this._xmlHash);
                  this.InsertChild(parent, (XmlDiffNode) xmlDiffCharData1);
                  break;
                case XmlNodeType.CDATA:
                                    var xmlDiffCharData2 = new XmlDiffCharData(++position, reader.Value, XmlDiffNodeType.CDATA);
                  xmlDiffCharData2.ComputeHashValue(this._xmlHash);
                  this.InsertChild(parent, (XmlDiffNode) xmlDiffCharData2);
                  break;
                case XmlNodeType.EntityReference:
                                    var xmlDiffEr = new XmlDiffER(++position, reader.Name);
                  xmlDiffEr.ComputeHashValue(this._xmlHash);
                  this.InsertChild(parent, (XmlDiffNode) xmlDiffEr);
                  break;
                case XmlNodeType.ProcessingInstruction:
                  ++position;
                  if (!this._XmlDiff.IgnorePI)
                  {
                                        var xmlDiffPi = new XmlDiffPI(position, reader.Name, reader.Value);
                    xmlDiffPi.ComputeHashValue(this._xmlHash);
                    this.InsertChild(parent, (XmlDiffNode) xmlDiffPi);
                    break;
                  }
                  break;
                case XmlNodeType.Comment:
                  ++position;
                  if (!this._XmlDiff.IgnoreComments)
                  {
                                        var xmlDiffCharData3 = new XmlDiffCharData(position, reader.Value, XmlDiffNodeType.Comment);
                    xmlDiffCharData3.ComputeHashValue(this._xmlHash);
                    this.InsertChild(parent, (XmlDiffNode) xmlDiffCharData3);
                    break;
                  }
                  break;
                case XmlNodeType.DocumentType:
                  ++position;
                  if (!this._XmlDiff.IgnoreDtd)
                  {
                                        var diffDocumentType = new XmlDiffDocumentType(position, reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                    diffDocumentType.ComputeHashValue(this._xmlHash);
                    this.InsertChild(parent, (XmlDiffNode) diffDocumentType);
                    break;
                  }
                  break;
                case XmlNodeType.SignificantWhitespace:
                  if (reader.XmlSpace == XmlSpace.Preserve)
                  {
                    ++position;
                    if (!this._XmlDiff.IgnoreWhitespace)
                    {
                                            var xmlDiffCharData3 = new XmlDiffCharData(position, reader.Value, XmlDiffNodeType.SignificantWhitespace);
                      xmlDiffCharData3.ComputeHashValue(this._xmlHash);
                      this.InsertChild(parent, (XmlDiffNode) xmlDiffCharData3);
                      break;
                    }
                    break;
                  }
                  break;
                case XmlNodeType.EndElement:
                  goto label_29;
                case XmlNodeType.XmlDeclaration:
                  ++position;
                  if (!this._XmlDiff.IgnoreXmlDecl)
                  {
                                        var diffXmlDeclaration = new XmlDiffXmlDeclaration(position, XmlDiff.NormalizeXmlDeclaration(reader.Value));
                    diffXmlDeclaration.ComputeHashValue(this._xmlHash);
                    this.InsertChild(parent, (XmlDiffNode) diffXmlDeclaration);
                    break;
                  }
                  break;
              }
            }
          }
          while (reader.Read());
        }
      }
label_29:
      this._curLastChild = curLastChild;
    }
Example #11
0
 internal XmlDiffNode LoadNode(XmlNode node, ref int childPosition)
 {
   switch (node.NodeType)
   {
     case XmlNodeType.Element:
                 var xmlDiffElement = new XmlDiffElement(++childPosition, node.LocalName, node.Prefix, node.NamespaceURI);
       this.LoadChildNodes((XmlDiffParentNode) xmlDiffElement, node);
       xmlDiffElement.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffElement;
     case XmlNodeType.Attribute:
       return (XmlDiffNode) null;
     case XmlNodeType.Text:
       var str = this._XmlDiff.IgnoreWhitespace ? XmlDiff.NormalizeText(node.Value) : node.Value;
                 var xmlDiffCharData1 = new XmlDiffCharData(++childPosition, str, XmlDiffNodeType.Text);
       xmlDiffCharData1.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffCharData1;
     case XmlNodeType.CDATA:
                 var xmlDiffCharData2 = new XmlDiffCharData(++childPosition, node.Value, XmlDiffNodeType.CDATA);
       xmlDiffCharData2.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffCharData2;
     case XmlNodeType.EntityReference:
                 var xmlDiffEr = new XmlDiffER(++childPosition, node.Name);
       xmlDiffEr.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffEr;
     case XmlNodeType.ProcessingInstruction:
       ++childPosition;
       if (this._XmlDiff.IgnorePI)
         return (XmlDiffNode) null;
                 var xmlDiffPi = new XmlDiffPI(childPosition, node.Name, node.Value);
       xmlDiffPi.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffPi;
     case XmlNodeType.Comment:
       ++childPosition;
       if (this._XmlDiff.IgnoreComments)
         return (XmlDiffNode) null;
                 var xmlDiffCharData3 = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.Comment);
       xmlDiffCharData3.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffCharData3;
     case XmlNodeType.DocumentType:
       ++childPosition;
       if (this._XmlDiff.IgnoreDtd)
         return (XmlDiffNode) null;
                 var xmlDocumentType = (XmlDocumentType) node;
                 var diffDocumentType = new XmlDiffDocumentType(childPosition, xmlDocumentType.Name, xmlDocumentType.PublicId, xmlDocumentType.SystemId, xmlDocumentType.InternalSubset);
       diffDocumentType.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) diffDocumentType;
     case XmlNodeType.SignificantWhitespace:
       ++childPosition;
       if (this._XmlDiff.IgnoreWhitespace)
         return (XmlDiffNode) null;
                 var xmlDiffCharData4 = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.SignificantWhitespace);
       xmlDiffCharData4.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) xmlDiffCharData4;
     case XmlNodeType.EndElement:
       return (XmlDiffNode) null;
     case XmlNodeType.XmlDeclaration:
       ++childPosition;
       if (this._XmlDiff.IgnoreXmlDecl)
         return (XmlDiffNode) null;
                 var diffXmlDeclaration = new XmlDiffXmlDeclaration(childPosition, XmlDiff.NormalizeXmlDeclaration(node.Value));
       diffXmlDeclaration.ComputeHashValue(this._xmlHash);
       return (XmlDiffNode) diffXmlDeclaration;
     default:
       return (XmlDiffNode) null;
   }
 }