コード例 #1
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;
        }