Beispiel #1
0
 /// <summary>
 /// Gets the list of nodes or attributes below the position indicated
 /// </summary>
 /// <param name="rootNode">The root node for the xml data</param>
 /// <param name="currentParentNode">The current node</param>
 /// <param name="xmlDiffPathExpr">Proprietary path statement separator or character</param>
 /// <returns>List of nodes or attributes</returns>
 public static XmlDiffPathNodeList SelectNodes(
     XmlDiffViewParentNode rootNode,
     XmlDiffViewParentNode currentParentNode,
     string xmlDiffPathExpr) {
     switch (xmlDiffPathExpr[0]) {
         case '/':
             return SelectAbsoluteNodes(rootNode, xmlDiffPathExpr);
         case '@':
             if (xmlDiffPathExpr.Length < 2) {
                 OnInvalidExpression(xmlDiffPathExpr);
             }
             if (xmlDiffPathExpr[1] == '*') {
                 return SelectAllAttributes(
                     (XmlDiffViewElement)currentParentNode);
             } else {
                 return SelectAttributes(
                     (XmlDiffViewElement)currentParentNode, xmlDiffPathExpr);
             }
         case '*':
             if (xmlDiffPathExpr.Length == 1) {
                 return SelectAllChildren(currentParentNode);
             } else {
                 OnInvalidExpression(xmlDiffPathExpr);
                 return null;
             }
         default:
             int startPosition = 0;
             return SelectChildNodes(
                 currentParentNode,
                 xmlDiffPathExpr,
                 startPosition);
     }
 }
 internal static XmlDiffPathNodeList SelectNodes( XmlDiffViewParentNode rootNode, XmlDiffViewParentNode currentParentNode, string xmlDiffPathExpr )
 {
     switch ( xmlDiffPathExpr[0] )
     {
         case '/':
             return SelectAbsoluteNodes( rootNode, xmlDiffPathExpr );
         case '@':
             if ( xmlDiffPathExpr.Length < 2 )
                 OnInvalidExpression( xmlDiffPathExpr );
             if ( xmlDiffPathExpr[1] == '*' )
                 return SelectAllAttributes( (XmlDiffViewElement)currentParentNode );
             else
                 return SelectAttributes( (XmlDiffViewElement)currentParentNode, xmlDiffPathExpr );
         case '*':
             if ( xmlDiffPathExpr.Length == 1 )
                 return SelectAllChildren( currentParentNode );
             else
             {
                 OnInvalidExpression( xmlDiffPathExpr );
                 return null;
             }
         default:
             return SelectChildNodes( currentParentNode, xmlDiffPathExpr, 0 );
     }
 }
 static XmlDiffPathNodeList SelectAllChildren(XmlDiffViewParentNode parentNode)
 {
     if (parentNode._childNodes == null)
     {
         OnNoMatchingNode("*");
         return(null);
     }
     else if (parentNode._childNodes._nextSibbling == null)
     {
         XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
         nodeList.AddNode(parentNode._childNodes);
         return(nodeList);
     }
     else
     {
         XmlDiffPathNodeList nodeList  = new XmlDiffPathMultiNodeList();
         XmlDiffViewNode     childNode = parentNode._childNodes;
         while (childNode != null)
         {
             nodeList.AddNode(childNode);
             childNode = childNode._nextSibbling;
         }
         return(nodeList);
     }
 }
Beispiel #4
0
        internal static XmlDiffPathNodeList SelectNodes(
            XmlDiffViewParentNode rootNode,
            XmlDiffViewParentNode currentParentNode,
            string xmlDiffPathExpr)
        {
            switch (xmlDiffPathExpr[0])
            {
            case '*':
                if (xmlDiffPathExpr.Length == 1)
                {
                    return(XmlDiffPath.SelectAllChildren(currentParentNode));
                }
                XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr);
                return((XmlDiffPathNodeList)null);

            case '/':
                return(XmlDiffPath.SelectAbsoluteNodes(rootNode, xmlDiffPathExpr));

            case '@':
                if (xmlDiffPathExpr.Length < 2)
                {
                    XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr);
                }
                return(xmlDiffPathExpr[1] == '*' ? XmlDiffPath.SelectAllAttributes((XmlDiffViewElement)currentParentNode) : XmlDiffPath.SelectAttributes((XmlDiffViewElement)currentParentNode, xmlDiffPathExpr));

            default:
                return(XmlDiffPath.SelectChildNodes(currentParentNode, xmlDiffPathExpr, 0));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets a list of node objects corresponding to
        /// the proprietary path reference provided.
        /// </summary>
        /// <param name="rootNode">The starting node</param>
        /// <param name="path">Absolute path reference to node of interest</param>
        /// <returns>list of node objects</returns>
        private static XmlDiffPathNodeList SelectAbsoluteNodes(
            XmlDiffViewParentNode rootNode,
            string path)
        {
            Debug.Assert(path[0] == '/');

            int             pos  = 1;
            XmlDiffViewNode node = rootNode;

            for (; ;)
            {
                int startPos = pos;
                int nodePos  = ReadPosition(path, ref pos);

                if (pos == path.Length || path[pos] == '/')
                {
                    if (node.FirstChildNode == null)
                    {
                        OnNoMatchingNode(path);
                    }

                    XmlDiffViewParentNode parentNode = (XmlDiffViewParentNode)node;
                    if (nodePos <= 0 || nodePos > parentNode.
                        SourceChildNodesCount)
                    {
                        OnNoMatchingNode(path);
                    }

                    node = parentNode.GetSourceChildNode(nodePos - 1);

                    if (pos == path.Length)
                    {
                        XmlDiffPathNodeList list = new
                                                   XmlDiffPathSingleNodeList();
                        list.AddNode(node);
                        return(list);
                    }

                    pos++;
                }
                else
                {
                    if (path[pos] == '-' || path[pos] == '|')
                    {
                        if (node.FirstChildNode == null)
                        {
                            OnNoMatchingNode(path);
                        }
                        return(SelectChildNodes(
                                   ((XmlDiffViewParentNode)node),
                                   path,
                                   startPos));
                    }

                    OnInvalidExpression(path);
                }
            }
        }
Beispiel #6
0
        private void OnRemove(XmlElement diffgramElement, XmlDiffPathNodeList matchNodes,
                              XmlDiffViewParentNode sourceParent, ref XmlDiffViewNode currentPosition)
        {
            // opid & descriptor
            XmlDiffViewOperation op = XmlDiffViewOperation.Remove;
            int opid = 0;
            OperationDescriptor opDesc = null;

            string opidAttr = diffgramElement.GetAttribute("opid");

            if (opidAttr != string.Empty)
            {
                opid   = int.Parse(opidAttr);
                opDesc = GetDescriptor(opid);
                if (opDesc._type == OperationDescriptor.Type.Move)
                {
                    op = XmlDiffViewOperation.MoveFrom;
                }
            }

            // subtree
            string subtreeAttr = diffgramElement.GetAttribute("subtree");
            bool   bSubtree    = (subtreeAttr != "no");

            if (!bSubtree)
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'remove' element must select a single node when the 'subtree' attribute is specified.");
                }
                // annotate node
                matchNodes.MoveNext();
                XmlDiffViewNode node = matchNodes.Current;
                AnnotateNode(node, op, opid, false);
                if (opid != 0)
                {
                    opDesc._nodeList.AddNode(node);
                }

                // recurse
                ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)node);
            }
            else
            {
                // annotate nodes
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    if (opid != 0)
                    {
                        opDesc._nodeList.AddNode(matchNodes.Current);
                    }
                    AnnotateNode(matchNodes.Current, op, opid, true);
                }
            }
        }
Beispiel #7
0
        private static XmlDiffPathNodeList SelectAbsoluteNodes(
            XmlDiffViewParentNode rootNode,
            string path)
        {
            Debug.Assert(path[0] == '/');
            var pos  = 1;
            var node = (XmlDiffViewNode)rootNode;
            int startPos;

            while (true)
            {
                startPos = pos;
                var num = XmlDiffPath.ReadPosition(path, ref pos);
                if (pos == path.Length || path[pos] == '/')
                {
                    if (node.FirstChildNode == null)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    var diffViewParentNode = (XmlDiffViewParentNode)node;
                    if (num <= 0 || num > diffViewParentNode._sourceChildNodesCount)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    node = diffViewParentNode.GetSourceChildNode(num - 1);
                    if (pos != path.Length)
                    {
                        ++pos;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (path[pos] != '-' && path[pos] != '|')
                {
                    XmlDiffPath.OnInvalidExpression(path);
                }
                else
                {
                    goto label_10;
                }
            }
            var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();

            diffPathNodeList.AddNode(node);
            return(diffPathNodeList);

label_10:
            if (node.FirstChildNode == null)
            {
                XmlDiffPath.OnNoMatchingNode(path);
            }
            return(XmlDiffPath.SelectChildNodes((XmlDiffViewParentNode)node, path, startPos));
        }
Beispiel #8
0
 private void OnAddFragment(
     XmlElement diffgramElement,
     XmlDiffViewParentNode sourceParent,
     ref XmlDiffViewNode currentPosition)
 {
     foreach (XmlNode childNode in diffgramElement.ChildNodes)
     {
         var xmlDiffViewNode = this.ImportNode(childNode);
         sourceParent.InsertChildAfter(xmlDiffViewNode, currentPosition, false);
         currentPosition = xmlDiffViewNode;
         this.AnnotateNode(xmlDiffViewNode, XmlDiffViewOperation.Add, 0, true);
     }
 }
Beispiel #9
0
        private void OnAddFragment(XmlElement diffgramElement, XmlDiffViewParentNode sourceParent, ref XmlDiffViewNode currentPosition)
        {
            IEnumerator childNodes = diffgramElement.ChildNodes.GetEnumerator();

            while (childNodes.MoveNext())
            {
                XmlDiffViewNode newChildNode = ImportNode((XmlNode)childNodes.Current);
                sourceParent.InsertChildAfter(newChildNode, currentPosition, false);
                currentPosition = newChildNode;

                AnnotateNode(newChildNode, XmlDiffViewOperation.Add, 0, true);
            }
        }
Beispiel #10
0
        private void OnRemove(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            var op   = XmlDiffViewOperation.Remove;
            var opid = 0;
            OperationDescriptor operationDescriptor = null;
            var attribute = diffgramElement.GetAttribute("opid");

            if (attribute != string.Empty)
            {
                opid = int.Parse(attribute);
                operationDescriptor = this.GetDescriptor(opid);
                if (operationDescriptor._type == OperationDescriptor.Type.Move)
                {
                    op = XmlDiffViewOperation.MoveFrom;
                }
            }
            if (!(diffgramElement.GetAttribute("subtree") != "no"))
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'remove' element must select a single node when the 'subtree' attribute is specified.");
                }
                matchNodes.MoveNext();
                var current = matchNodes.Current;
                this.AnnotateNode(current, op, opid, false);
                if (opid != 0)
                {
                    operationDescriptor._nodeList.AddNode(current);
                }
                this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)current);
            }
            else
            {
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    if (opid != 0)
                    {
                        operationDescriptor._nodeList.AddNode(matchNodes.Current);
                    }
                    this.AnnotateNode(matchNodes.Current, op, opid, true);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Gets the list of nodes or attributes below the position indicated
        /// </summary>
        /// <param name="rootNode">The root node for the xml data</param>
        /// <param name="currentParentNode">The current node</param>
        /// <param name="xmlDiffPathExpr">Proprietary path statement separator or character</param>
        /// <returns>List of nodes or attributes</returns>
        public static XmlDiffPathNodeList SelectNodes(
            XmlDiffViewParentNode rootNode,
            XmlDiffViewParentNode currentParentNode,
            string xmlDiffPathExpr)
        {
            switch (xmlDiffPathExpr[0])
            {
            case '/':
                return(SelectAbsoluteNodes(rootNode, xmlDiffPathExpr));

            case '@':
                if (xmlDiffPathExpr.Length < 2)
                {
                    OnInvalidExpression(xmlDiffPathExpr);
                }
                if (xmlDiffPathExpr[1] == '*')
                {
                    return(SelectAllAttributes(
                               (XmlDiffViewElement)currentParentNode));
                }
                else
                {
                    return(SelectAttributes(
                               (XmlDiffViewElement)currentParentNode, xmlDiffPathExpr));
                }

            case '*':
                if (xmlDiffPathExpr.Length == 1)
                {
                    return(SelectAllChildren(currentParentNode));
                }
                else
                {
                    OnInvalidExpression(xmlDiffPathExpr);
                    return(null);
                }

            default:
                int startPosition = 0;
                return(SelectChildNodes(
                           currentParentNode,
                           xmlDiffPathExpr,
                           startPosition));
            }
        }
Beispiel #12
0
        private void OnAddMatch(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            var attribute = diffgramElement.GetAttribute("opid");

            if (attribute == string.Empty)
            {
                throw new Exception("Missing opid attribute.");
            }
            var opid       = int.Parse(attribute);
            var descriptor = this.GetDescriptor(opid);

            if (!(diffgramElement.GetAttribute("subtree") != "no"))
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'add' element must select a single node when the 'subtree' attribute is specified.");
                }
                matchNodes.MoveNext();
                var xmlDiffViewNode = matchNodes.Current.Clone(false);
                this.AnnotateNode(xmlDiffViewNode, XmlDiffViewOperation.MoveTo, opid, true);
                descriptor._nodeList.AddNode(xmlDiffViewNode);
                sourceParent.InsertChildAfter(xmlDiffViewNode, currentPosition, false);
                currentPosition = xmlDiffViewNode;
                this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)xmlDiffViewNode);
            }
            else
            {
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    var xmlDiffViewNode = matchNodes.Current.Clone(true);
                    this.AnnotateNode(xmlDiffViewNode, XmlDiffViewOperation.MoveTo, opid, true);
                    descriptor._nodeList.AddNode(xmlDiffViewNode);
                    sourceParent.InsertChildAfter(xmlDiffViewNode, currentPosition, false);
                    currentPosition = xmlDiffViewNode;
                }
            }
        }
Beispiel #13
0
        private static XmlDiffPathNodeList SelectAllChildren(
            XmlDiffViewParentNode parentNode)
        {
            if (parentNode._childNodes == null)
            {
                XmlDiffPath.OnNoMatchingNode("*");
                return((XmlDiffPathNodeList)null);
            }
            if (parentNode._childNodes._nextSibbling == null)
            {
                var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                diffPathNodeList.AddNode(parentNode._childNodes);
                return(diffPathNodeList);
            }
            var diffPathNodeList1 = (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList();

            for (var node = parentNode._childNodes; node != null; node = node._nextSibbling)
            {
                diffPathNodeList1.AddNode(node);
            }
            return(diffPathNodeList1);
        }
        static XmlDiffPathNodeList SelectChildNodes(XmlDiffViewParentNode parentNode, string path, int startPos)
        {
            int pos = startPos;
            XmlDiffPathNodeList nodeList = null;

            for (;;)
            {
                int nodePos = ReadPosition(path, ref pos);

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

                if (nodePos <= 0 || nodePos > parentNode._sourceChildNodesCount)
                {
                    OnNoMatchingNode(path);
                }

                nodeList.AddNode(parentNode.GetSourceChildNode(nodePos - 1));

                if (pos == path.Length)
                {
                    break;
                }
                else if (path[pos] == '|')
                {
                    pos++;
                }
                else if (path[pos] == '-')
                {
                    pos++;
                    int endNodePos = ReadPosition(path, ref pos);
                    if (endNodePos <= 0 || endNodePos > parentNode._sourceChildNodesCount)
                    {
                        OnNoMatchingNode(path);
                    }

                    while (nodePos < endNodePos)
                    {
                        nodePos++;
                        nodeList.AddNode(parentNode.GetSourceChildNode(nodePos - 1));
                    }

                    if (pos == path.Length)
                    {
                        break;
                    }
                    else if (path[pos] == '|')
                    {
                        pos++;
                    }
                    else
                    {
                        OnInvalidExpression(path);
                    }
                }
            }
            return(nodeList);
        }
Beispiel #15
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;
            }
        }
Beispiel #16
0
        private void OnAddMatch(XmlElement diffgramElement, XmlDiffPathNodeList matchNodes, XmlDiffViewParentNode sourceParent,
                                ref XmlDiffViewNode currentPosition)
        {
            string opidAttr = diffgramElement.GetAttribute("opid");

            if (opidAttr == string.Empty)
            {
                throw new Exception("Missing opid attribute.");
            }

            // opid & descriptor
            int opid = int.Parse(opidAttr);
            OperationDescriptor opDesc = GetDescriptor(opid);

            string subtreeAttr = diffgramElement.GetAttribute("subtree");
            bool   bSubtree    = (subtreeAttr != "no");

            // move single node without subtree
            if (!bSubtree)
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'add' element must select a single node when the 'subtree' attribute is specified.");
                }

                // clone node
                matchNodes.MoveNext();
                XmlDiffViewNode newNode = matchNodes.Current.Clone(false);
                AnnotateNode(newNode, XmlDiffViewOperation.MoveTo, opid, true);

                opDesc._nodeList.AddNode(newNode);

                // insert in tree
                sourceParent.InsertChildAfter(newNode, currentPosition, false);
                currentPosition = newNode;

                // recurse
                ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)newNode);
            }
            // move subtree
            else
            {
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    XmlDiffViewNode newNode = matchNodes.Current.Clone(true);
                    AnnotateNode(newNode, XmlDiffViewOperation.MoveTo, opid, true);

                    opDesc._nodeList.AddNode(newNode);

                    sourceParent.InsertChildAfter(newNode, currentPosition, false);
                    currentPosition = newNode;
                }
            }
        }
Beispiel #17
0
 /// <summary>
 /// Gets a list of all node objects at and below the location
 /// specified.
 /// </summary>
 /// <param name="parentNode">Node at which to start</param>
 /// <returns>list of node objects</returns>
 private static XmlDiffPathNodeList SelectAllChildren(
     XmlDiffViewParentNode parentNode) {
     if (parentNode.ChildNodes == null) {
         OnNoMatchingNode("*");
         return null;
     } else if (parentNode.ChildNodes.NextSibbling == null) {
         XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
         nodeList.AddNode(parentNode.ChildNodes);
         return nodeList;
     } else {
         XmlDiffPathNodeList nodeList = new XmlDiffPathMultiNodeList();
         XmlDiffViewNode childNode = parentNode.ChildNodes;
         while (childNode != null) {
             nodeList.AddNode(childNode);
             childNode = childNode.NextSibbling;
         }
         return nodeList;
     }
 }
Beispiel #18
0
        private void ApplyDiffgram(XmlNode diffgramParent, XmlDiffViewParentNode sourceParent)
        {
            sourceParent.CreateSourceNodesIndex();
            XmlDiffViewNode currentPosition = null;

            IEnumerator diffgramChildren = diffgramParent.ChildNodes.GetEnumerator();

            while (diffgramChildren.MoveNext())
            {
                XmlNode diffgramNode = (XmlNode)diffgramChildren.Current;
                if (diffgramNode.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                XmlElement diffgramElement = diffgramChildren.Current as XmlElement;
                if (diffgramElement == null)
                {
                    throw new Exception("Invalid node in diffgram.");
                }

                if (diffgramElement.NamespaceURI != XmlDiff.NamespaceUri)
                {
                    throw new Exception("Invalid element in diffgram.");
                }

                string matchAttr = diffgramElement.GetAttribute("match");
                XmlDiffPathNodeList matchNodes = null;
                if (matchAttr != string.Empty)
                {
                    matchNodes = XmlDiffPath.SelectNodes(_doc, sourceParent, matchAttr);
                }

                switch (diffgramElement.LocalName)
                {
                case "node":
                    if (matchNodes.Count != 1)
                    {
                        throw new Exception("The 'match' attribute of 'node' element must select a single node.");
                    }
                    matchNodes.MoveNext();
                    if (diffgramElement.ChildNodes.Count > 0)
                    {
                        ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)matchNodes.Current);
                    }
                    currentPosition = matchNodes.Current;
                    break;

                case "add":
                    if (matchAttr != string.Empty)
                    {
                        OnAddMatch(diffgramElement, matchNodes, sourceParent, ref currentPosition);
                    }
                    else
                    {
                        string typeAttr = diffgramElement.GetAttribute("type");
                        if (typeAttr != string.Empty)
                        {
                            OnAddNode(diffgramElement, typeAttr, sourceParent, ref currentPosition);
                        }
                        else
                        {
                            OnAddFragment(diffgramElement, sourceParent, ref currentPosition);
                        }
                    }
                    break;

                case "remove":
                    OnRemove(diffgramElement, matchNodes, sourceParent, ref currentPosition);
                    break;

                case "change":
                    OnChange(diffgramElement, matchNodes, sourceParent, ref currentPosition);
                    break;
                }
            }
        }
Beispiel #19
0
        private void ApplyDiffgram(XmlNode diffgramParent, XmlDiffViewParentNode sourceParent)
        {
            sourceParent.CreateSourceNodesIndex();
            XmlDiffViewNode currentPosition = null;
            var             enumerator      = diffgramParent.ChildNodes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (((XmlNode)enumerator.Current).NodeType != XmlNodeType.Comment)
                {
                    if (!(enumerator.Current is XmlElement))
                    {
                        throw new Exception("Invalid node in diffgram.");
                    }
                    var current = enumerator.Current as XmlElement;
                    if (current.NamespaceURI != "http://schemas.microsoft.com/xmltools/2002/xmldiff")
                    {
                        throw new Exception("Invalid element in diffgram.");
                    }
                    var attribute1 = current.GetAttribute("match");
                    XmlDiffPathNodeList matchNodes = null;
                    if (attribute1 != string.Empty)
                    {
                        matchNodes = XmlDiffPath.SelectNodes(this._doc, sourceParent, attribute1);
                    }
                    switch (current.LocalName)
                    {
                    case "node":
                        if (matchNodes.Count != 1)
                        {
                            throw new Exception("The 'match' attribute of 'node' element must select a single node.");
                        }
                        matchNodes.MoveNext();
                        if (current.ChildNodes.Count > 0)
                        {
                            this.ApplyDiffgram(current, (XmlDiffViewParentNode)matchNodes.Current);
                        }
                        currentPosition = matchNodes.Current;
                        continue;

                    case "add":
                        if (attribute1 != string.Empty)
                        {
                            this.OnAddMatch(current, matchNodes, sourceParent, ref currentPosition);
                            continue;
                        }
                        var attribute2 = current.GetAttribute("type");
                        if (attribute2 != string.Empty)
                        {
                            this.OnAddNode(current, attribute2, sourceParent, ref currentPosition);
                            continue;
                        }
                        this.OnAddFragment(current, sourceParent, ref currentPosition);
                        continue;

                    case "remove":
                        this.OnRemove(current, matchNodes, sourceParent, ref currentPosition);
                        continue;

                    case "change":
                        this.OnChange(current, matchNodes, sourceParent, ref currentPosition);
                        continue;

                    default:
                        continue;
                    }
                }
            }
        }
        /// <summary>
        /// Tag the relocated data 
        /// </summary>
        /// <param name="diffgramElement">node in diffgram</param>
        /// <param name="matchNodes">the path to the baseline node</param>
        /// <param name="sourceParent">the baseline parent node</param>
        /// <param name="currentPosition">the resulting node</param>
        private void OnRemove(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            // opid & descriptor
            XmlDiffViewOperation operation = XmlDiffViewOperation.Remove;
            int operationId = 0;
            OperationDescriptor operationDesc = null;

            string opidAttr = diffgramElement.GetAttribute("opid");
            if (opidAttr != string.Empty) {
                operationId = int.Parse(opidAttr);
                operationDesc = this.GetDescriptor(operationId);
                if (operationDesc.OperationType == OperationDescriptor.Type.Move) {
                    operation = XmlDiffViewOperation.MoveFrom;
                }
            } else {
                operationId = NextOperationId;
            }

            // subtree
            string subtreeAttr = diffgramElement.GetAttribute("subtree");
            bool subtree = (subtreeAttr != "no");
            if (!subtree)
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'remove' " +
                        "element must select a single node when the 'subtree' " +
                        "attribute is specified.");
                }

                // annotate node
                matchNodes.MoveNext();
                XmlDiffViewNode node = matchNodes.Current;
                this.AnnotateNode(node, operation, operationId, false);
                if (operationId != 0 && operationDesc != null)
                {
                    operationDesc.NodeList.AddNode(node);
                }

                // recurse
                this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)node);
            }
            else
            {
                // annotate nodes
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    if (operationId != 0 && operationDesc != null)
                    {
                        operationDesc.NodeList.AddNode(matchNodes.Current);
                    }
                    this.AnnotateNode(matchNodes.Current, operation, operationId, true);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Gets the list of child nodes below the position indicated
        /// </summary>
        /// <param name="parentNode">The current node</param>
        /// <param name="path">Proprietary path statement</param>
        /// <param name="startPos">Position in the path statement 
        /// at which to start collecting node objects.</param>
        /// <returns>list of child nodes</returns>
        /// <returns>List of nodes or attributes</returns>
        private static XmlDiffPathNodeList SelectChildNodes(
            XmlDiffViewParentNode parentNode,
            string path,
            int startPos) {
            int pos = startPos;
            XmlDiffPathNodeList nodeList = null;

            for (; ; ) {
                int nodePos = ReadPosition(path, ref pos);

                if (pos == path.Length) {
                    nodeList = new XmlDiffPathSingleNodeList();
                } else {
                    nodeList = new XmlDiffPathMultiNodeList();
                }
                if (nodePos <= 0 || nodePos > parentNode.SourceChildNodesCount) {
                    OnNoMatchingNode(path);
                }
                nodeList.AddNode(parentNode.GetSourceChildNode(nodePos - 1));

                if (pos == path.Length) {
                    break;
                } else if (path[pos] == '|') {
                    pos++;
                } else if (path[pos] == '-') {
                    pos++;
                    int endNodePos = ReadPosition(path, ref pos);
                    if (endNodePos <= 0 || endNodePos > parentNode.SourceChildNodesCount) {
                        OnNoMatchingNode(path);
                    }
                    while (nodePos < endNodePos) {
                        nodePos++;
                        nodeList.AddNode(parentNode.GetSourceChildNode(nodePos - 1));
                    }

                    if (pos == path.Length) {
                        break;
                    } else if (path[pos] == '|') {
                        pos++;
                    } else {
                        OnInvalidExpression(path);
                    }
                }
            }
            return nodeList;
        }
        /// <summary>
        /// Add the new fragment 
        /// </summary>
        /// <param name="diffgramElement">node in diffgram</param>
        /// <param name="sourceParent">the baseline parent node</param>
        /// <param name="currentPosition">the resulting node</param>
        private void OnAddFragment(
            XmlElement diffgramElement,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            int opid = NextOperationId;
            IEnumerator childNodes =
                diffgramElement.ChildNodes.GetEnumerator();
            while (childNodes.MoveNext())
            {
                XmlDiffViewNode newChildNode = this.ImportNode(
                    (XmlNode)childNodes.Current);
                sourceParent.InsertChildAfter(
                    newChildNode,
                    currentPosition,
                    false);
                currentPosition = newChildNode;

                this.AnnotateNode(
                    newChildNode,
                    XmlDiffViewOperation.Add,
                    opid,
                    true);
            }
        }
        /// <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;
        }
Beispiel #24
0
        /// <summary>
        /// Gets a list of node objects corresponding to
        /// the proprietary path reference provided. 
        /// </summary>
        /// <param name="rootNode">The starting node</param>
        /// <param name="path">Absolute path reference to node of interest</param>
        /// <returns>list of node objects</returns>
        private static XmlDiffPathNodeList SelectAbsoluteNodes(
            XmlDiffViewParentNode rootNode,
            string path) {
            Debug.Assert(path[0] == '/');

            int pos = 1;
            XmlDiffViewNode node = rootNode;

            for (; ; ) {
                int startPos = pos;
                int nodePos = ReadPosition(path, ref pos);

                if (pos == path.Length || path[pos] == '/') {
                    if (node.FirstChildNode == null) {
                        OnNoMatchingNode(path);
                    }

                    XmlDiffViewParentNode parentNode = (XmlDiffViewParentNode)node;
                    if (nodePos <= 0 || nodePos > parentNode.
                        SourceChildNodesCount) {
                        OnNoMatchingNode(path);
                    }

                    node = parentNode.GetSourceChildNode(nodePos - 1);

                    if (pos == path.Length) {
                        XmlDiffPathNodeList list = new
                            XmlDiffPathSingleNodeList();
                        list.AddNode(node);
                        return list;
                    }

                    pos++;
                } else {
                    if (path[pos] == '-' || path[pos] == '|') {
                        if (node.FirstChildNode == null) {
                            OnNoMatchingNode(path);
                        }
                        return SelectChildNodes(
                            ((XmlDiffViewParentNode)node),
                            path,
                            startPos);
                    }

                    OnInvalidExpression(path);
                }
            }
        }
Beispiel #25
0
        private void OnChange(XmlElement diffgramElement, XmlDiffPathNodeList matchNodes,
                              XmlDiffViewParentNode sourceParent, ref XmlDiffViewNode currentPosition)
        {
            Debug.Assert(matchNodes.Count == 1);
            matchNodes.Reset();
            matchNodes.MoveNext();
            XmlDiffViewNode node = matchNodes.Current;

            if (node._nodeType != XmlNodeType.Attribute)
            {
                currentPosition = node;
            }

            XmlDiffViewNode.ChangeInfo changeInfo = new XmlDiffViewNode.ChangeInfo();
            string name   = diffgramElement.HasAttribute("name") ? diffgramElement.GetAttribute("name") : null;
            string prefix = diffgramElement.HasAttribute("prefix") ? diffgramElement.GetAttribute("prefix") : null;
            string ns     = diffgramElement.HasAttribute("ns") ? diffgramElement.GetAttribute("ns") : null;

            switch (node._nodeType)
            {
            case XmlNodeType.Element:
                changeInfo._localName = (name == null)? ((XmlDiffViewElement)node)._localName : name;
                changeInfo._prefix    = (prefix == null) ? ((XmlDiffViewElement)node)._prefix : prefix;
                changeInfo._ns        = (ns == null) ? ((XmlDiffViewElement)node)._ns : ns;
                break;

            case XmlNodeType.Attribute:
                string value = diffgramElement.InnerText;
                if (name == string.Empty && prefix == string.Empty && value == string.Empty)
                {
                    return;
                }
                changeInfo._localName = (name == null) ? ((XmlDiffViewAttribute)node)._localName : name;
                changeInfo._prefix    = (prefix == null) ? ((XmlDiffViewAttribute)node)._prefix      : prefix;
                changeInfo._ns        = (ns == null) ? ((XmlDiffViewAttribute)node)._ns : ns;
                changeInfo._value     = diffgramElement.InnerText;
                break;

            case XmlNodeType.Text:
            case XmlNodeType.CDATA:
                Debug.Assert(diffgramElement.FirstChild != null);
                changeInfo._value = diffgramElement.InnerText;
                break;

            case XmlNodeType.Comment:
                Debug.Assert(diffgramElement.FirstChild != null);
                Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.Comment);
                changeInfo._value = diffgramElement.FirstChild.Value;
                break;

            case XmlNodeType.ProcessingInstruction:
                if (name == null)
                {
                    Debug.Assert(diffgramElement.FirstChild != null);
                    Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.ProcessingInstruction);
                    changeInfo._localName = diffgramElement.FirstChild.Name;
                    changeInfo._value     = diffgramElement.FirstChild.Value;
                }
                else
                {
                    changeInfo._localName = name;
                    changeInfo._value     = ((XmlDiffViewPI)node)._value;
                }
                break;

            case XmlNodeType.EntityReference:
                Debug.Assert(name != null);
                changeInfo._localName = name;
                break;

            case XmlNodeType.XmlDeclaration:
                Debug.Assert(diffgramElement.FirstChild != null);
                changeInfo._value = diffgramElement.InnerText;
                break;

            case XmlNodeType.DocumentType:
                changeInfo._localName = (name == null) ? ((XmlDiffViewDocumentType)node)._name : name;

                if (diffgramElement.HasAttribute("publicId"))
                {
                    changeInfo._prefix = diffgramElement.GetAttribute("publicId");
                }
                else
                {
                    changeInfo._prefix = ((XmlDiffViewDocumentType)node)._publicId;
                }

                if (diffgramElement.HasAttribute("systemId"))
                {
                    changeInfo._ns = diffgramElement.GetAttribute("systemId");
                }
                else
                {
                    changeInfo._ns = ((XmlDiffViewDocumentType)node)._systemId;
                }

                if (diffgramElement.FirstChild != null)
                {
                    changeInfo._value = diffgramElement.InnerText;
                }
                else
                {
                    changeInfo._value = ((XmlDiffViewDocumentType)node)._subset;
                }
                break;

            default:
                Debug.Assert(false, "Invalid node type.");
                break;
            }
            node._changeInfo = changeInfo;
            node._op         = XmlDiffViewOperation.Change;

            string opidAttr = diffgramElement.GetAttribute("opid");

            if (opidAttr != string.Empty)
            {
                node._opid = int.Parse(opidAttr);
            }

            if (node._nodeType == XmlNodeType.Element &&
                diffgramElement.FirstChild != null)
            {
                ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)node);
            }
        }
        /// <summary>
        /// Loops through the child nodes of the diffgram and
        /// annotates the nodes with the type of operation, e.g., 
        /// add, change, remove, etc.
        /// </summary>
        /// <param name="diffgramParent">node in diffgram data</param>
        /// <param name="sourceParent">node in baseline data</param>
        private void ApplyDiffgram(
            XmlNode diffgramParent,
            XmlDiffViewParentNode sourceParent)
        {
            sourceParent.CreateSourceNodesIndex();
            XmlDiffViewNode currentPosition = null;

            IEnumerator diffgramChildren =
                diffgramParent.ChildNodes.GetEnumerator();
            while (diffgramChildren.MoveNext())
            {
                XmlNode diffgramNode = (XmlNode)diffgramChildren.Current;
                if (diffgramNode.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                XmlElement diffgramElement =
                    diffgramChildren.Current as XmlElement;
                if (diffgramElement == null)
                {
                    Trace.WriteLine("Invalid node in diffgram.");
                    throw new InvalidOperationException(
                        "Invalid node in diffgram.");
                }

                if (diffgramElement.NamespaceURI != XmlDiff.NamespaceUri)
                {
                    Trace.WriteLine("Invalid element in diffgram.");
                    throw new InvalidOperationException(
                        "Invalid element in diffgram.");
                }

                string matchAttr = diffgramElement.GetAttribute("match");
                XmlDiffPathNodeList matchNodes = null;
                if (matchAttr != string.Empty)
                {
                    matchNodes = XmlDiffPath.SelectNodes(
                    this.viewDocument,
                    sourceParent,
                    matchAttr);
                }

                switch (diffgramElement.LocalName)
                {
                    case "node":
                        if (matchNodes.Count != 1)
                        {
                            string message = "The 'match' attribute of " +
                                "'node' element must select a single node.";
                            throw new InvalidOperationException(message);
                        }

                        matchNodes.MoveNext();
                        if (diffgramElement.ChildNodes.Count > 0)
                        {
                            this.ApplyDiffgram(
                                diffgramElement,
                                (XmlDiffViewParentNode)matchNodes.Current);
                        }

                        currentPosition = matchNodes.Current;
                        break;
                    case "add":
                        if (matchAttr != string.Empty)
                        {
                            this.OnAddMatch(
                                diffgramElement,
                                matchNodes,
                                sourceParent,
                                ref currentPosition);
                        }
                        else
                        {
                            string typeAttr = diffgramElement.GetAttribute(
                                "type");
                            if (typeAttr != string.Empty)
                            {
                                this.OnAddNode(
                                    diffgramElement,
                                    typeAttr,
                                    sourceParent,
                                    ref currentPosition);
                            }
                            else
                            {
                                this.OnAddFragment(
                                    diffgramElement,
                                    sourceParent,
                                    ref currentPosition);
                            }
                        }
                        break;
                    case "remove":
                        this.OnRemove(
                            diffgramElement,
                            matchNodes,
                            sourceParent,
                            ref currentPosition);
                        break;
                    case "change":
                        this.OnChange(
                            diffgramElement,
                            matchNodes,
                            sourceParent,
                            ref currentPosition);
                        break;
                }
            }
        }
Beispiel #27
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;
        }
Beispiel #28
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;
        }
        /// <summary>
        /// Relocate matched data. 
        /// </summary>
        /// <param name="diffgramElement">node in diffgram</param>
        /// <param name="matchNodes">the path to the baseline node</param>
        /// <param name="sourceParent">the baseline parent node</param>
        /// <param name="currentPosition">the resulting node</param>
        private void OnAddMatch(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            string opidAttr = diffgramElement.GetAttribute("opid");
            if (opidAttr == string.Empty)
            {
                throw new Exception("Missing opid attribute.");
            }

            // opid & descriptor
            int opid = ParseOpId(opidAttr);
            OperationDescriptor operationDesc = this.GetDescriptor(opid);

            string subtreeAttr = diffgramElement.GetAttribute("subtree");
            bool subtree = (subtreeAttr != "no");

            // move single node without subtree
            if (!subtree)
            {
                if (matchNodes.Count != 1)
                {
                    throw new Exception("The 'match' attribute of 'add' " +
                        "element must select a single node when the 'subtree' " +
                        "attribute is specified.");
                }

                // clone node
                matchNodes.MoveNext();
                XmlDiffViewNode newNode = matchNodes.Current.Clone(false);
                this.AnnotateNode(
                    newNode,
                    XmlDiffViewOperation.MoveTo,
                    opid,
                    true);

                operationDesc.NodeList.AddNode(newNode);

                // insert in tree
                sourceParent.InsertChildAfter(newNode, currentPosition, false);
                currentPosition = newNode;

                // recurse
                this.ApplyDiffgram(
                    diffgramElement,
                    (XmlDiffViewParentNode)newNode);
            }
            else
            {
                // move subtree
                matchNodes.Reset();
                while (matchNodes.MoveNext())
                {
                    XmlDiffViewNode newNode = matchNodes.Current.Clone(true);
                    this.AnnotateNode(
                        newNode,
                        XmlDiffViewOperation.MoveTo,
                        opid,
                        true);

                    operationDesc.NodeList.AddNode(newNode);

                    sourceParent.InsertChildAfter(newNode, currentPosition, false);
                    currentPosition = newNode;
                }
            }
        }
Beispiel #30
0
        private static XmlDiffPathNodeList SelectChildNodes(
            XmlDiffViewParentNode parentNode,
            string path,
            int startPos)
        {
            var pos = startPos;
            XmlDiffPathNodeList diffPathNodeList;

            while (true)
            {
                int num1;
                do
                {
                    num1             = XmlDiffPath.ReadPosition(path, ref pos);
                    diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                    if (num1 <= 0 || num1 > parentNode._sourceChildNodesCount)
                    {
                        XmlDiffPath.OnNoMatchingNode(path);
                    }
                    diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1));
                    if (pos != path.Length)
                    {
                        if (path[pos] == '|')
                        {
                            ++pos;
                        }
                    }
                    else
                    {
                        goto label_15;
                    }
                }while (path[pos] != '-');
                ++pos;
                var num2 = XmlDiffPath.ReadPosition(path, ref pos);
                if (num2 <= 0 || num2 > parentNode._sourceChildNodesCount)
                {
                    XmlDiffPath.OnNoMatchingNode(path);
                }
                while (num1 < num2)
                {
                    ++num1;
                    diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1));
                }
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        ++pos;
                    }
                    else
                    {
                        XmlDiffPath.OnInvalidExpression(path);
                    }
                }
                else
                {
                    break;
                }
            }
label_15:
            return(diffPathNodeList);
        }
Beispiel #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;
            }
        }
        /// <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;
            }
        }
Beispiel #33
0
        private void OnChange(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            Debug.Assert(matchNodes.Count == 1);
            matchNodes.Reset();
            matchNodes.MoveNext();
            var current = matchNodes.Current;

            if (current._nodeType != XmlNodeType.Attribute)
            {
                currentPosition = current;
            }
            var changeInfo = new XmlDiffViewNode.ChangeInfo();
            var str1       = diffgramElement.HasAttribute("name") ? diffgramElement.GetAttribute("name") : null;
            var str2       = diffgramElement.HasAttribute("prefix") ? diffgramElement.GetAttribute("prefix") : null;
            var str3       = diffgramElement.HasAttribute("ns") ? diffgramElement.GetAttribute("ns") : null;

            switch (current._nodeType)
            {
            case XmlNodeType.Element:
                changeInfo._localName = str1 == null ? ((XmlDiffViewElement)current)._localName : str1;
                changeInfo._prefix    = str2 == null ? ((XmlDiffViewElement)current)._prefix : str2;
                changeInfo._ns        = str3 == null ? ((XmlDiffViewElement)current)._ns : str3;
                break;

            case XmlNodeType.Attribute:
                var innerText = diffgramElement.InnerText;
                if (str1 == string.Empty && str2 == string.Empty && innerText == string.Empty)
                {
                    return;
                }
                changeInfo._localName = str1 == null ? ((XmlDiffViewAttribute)current)._localName : str1;
                changeInfo._prefix    = str2 == null ? ((XmlDiffViewAttribute)current)._prefix : str2;
                changeInfo._ns        = str3 == null ? ((XmlDiffViewAttribute)current)._ns : str3;
                changeInfo._value     = diffgramElement.InnerText;
                break;

            case XmlNodeType.Text:
            case XmlNodeType.CDATA:
                Debug.Assert(diffgramElement.FirstChild != null);
                changeInfo._value = diffgramElement.InnerText;
                break;

            case XmlNodeType.EntityReference:
                Debug.Assert(str1 != null);
                changeInfo._localName = str1;
                break;

            case XmlNodeType.ProcessingInstruction:
                if (str1 == null)
                {
                    Debug.Assert(diffgramElement.FirstChild != null);
                    Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.ProcessingInstruction);
                    changeInfo._localName = diffgramElement.FirstChild.Name;
                    changeInfo._value     = diffgramElement.FirstChild.Value;
                    break;
                }
                changeInfo._localName = str1;
                changeInfo._value     = ((XmlDiffViewCharData)current)._value;
                break;

            case XmlNodeType.Comment:
                Debug.Assert(diffgramElement.FirstChild != null);
                Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.Comment);
                changeInfo._value = diffgramElement.FirstChild.Value;
                break;

            case XmlNodeType.DocumentType:
                changeInfo._localName = str1 == null ? ((XmlDiffViewDocumentType)current)._name : str1;
                changeInfo._prefix    = !diffgramElement.HasAttribute("publicId") ? ((XmlDiffViewDocumentType)current)._publicId : diffgramElement.GetAttribute("publicId");
                changeInfo._ns        = !diffgramElement.HasAttribute("systemId") ? ((XmlDiffViewDocumentType)current)._systemId : diffgramElement.GetAttribute("systemId");
                changeInfo._value     = diffgramElement.FirstChild == null ? ((XmlDiffViewDocumentType)current)._subset : diffgramElement.InnerText;
                break;

            case XmlNodeType.XmlDeclaration:
                Debug.Assert(diffgramElement.FirstChild != null);
                changeInfo._value = diffgramElement.InnerText;
                break;

            default:
                Debug.Assert(false, "Invalid node type.");
                break;
            }
            current._changeInfo = changeInfo;
            current._op         = XmlDiffViewOperation.Change;
            var attribute = diffgramElement.GetAttribute("opid");

            if (attribute != string.Empty)
            {
                current._opid = int.Parse(attribute);
            }
            if (current._nodeType != XmlNodeType.Element || diffgramElement.FirstChild == null)
            {
                return;
            }
            this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)current);
        }
        /// <summary>
        /// Store changes in the ChangeInfo object of the marked-up-baseline node
        /// </summary>
        /// <param name="diffgramElement">current element in the diffgram</param>
        /// <param name="matchNodes">Object containing the list of baseline nodes
        ///  which match the position in the diffgram</param>
        /// <param name="sourceParent">parent node in the baseline data</param>
        /// <param name="currentPosition">current position</param>
        private void OnChange(
            XmlElement diffgramElement,
            XmlDiffPathNodeList matchNodes,
            XmlDiffViewParentNode sourceParent,
            ref XmlDiffViewNode currentPosition)
        {
            Debug.Assert(matchNodes.Count == 1);
            matchNodes.Reset();
            matchNodes.MoveNext();
            XmlDiffViewNode node = matchNodes.Current;

            if (node.NodeType != XmlNodeType.Attribute)
            {
                currentPosition = node;
            }
            XmlDiffViewNode.ChangeInfo changeInfo = new XmlDiffViewNode.ChangeInfo();
            string name = diffgramElement.HasAttribute("name") ? diffgramElement.GetAttribute("name") : null;
            string prefix = diffgramElement.HasAttribute("prefix") ? diffgramElement.GetAttribute("prefix") : null;
            string ns = diffgramElement.HasAttribute("ns") ? diffgramElement.GetAttribute("ns") : null;

            switch (node.NodeType)
            {
                case XmlNodeType.Element:
                    changeInfo.LocalName = (name == null) ? ((XmlDiffViewElement)node).LocalName : name;
                    changeInfo.Prefix = (prefix == null) ? ((XmlDiffViewElement)node).Prefix : prefix;
                    changeInfo.NamespaceUri = (ns == null) ? ((XmlDiffViewElement)node).NamespaceUri : ns;
                    break;
                case XmlNodeType.Attribute:
                    string value = diffgramElement.InnerText;
                    if (name == string.Empty && prefix == string.Empty && value == string.Empty)
                    {
                        return;
                    }
                    changeInfo.LocalName = (name == null) ? ((XmlDiffViewAttribute)node).LocalName : name;
                    changeInfo.Prefix = (prefix == null) ? ((XmlDiffViewAttribute)node).Prefix : prefix;
                    changeInfo.NamespaceUri = (ns == null) ? ((XmlDiffViewAttribute)node).NamespaceUri : ns;
                    changeInfo.Subset = diffgramElement.InnerText;
                    break;
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    Debug.Assert(diffgramElement.FirstChild != null);
                    changeInfo.Subset = diffgramElement.InnerText;
                    break;
                case XmlNodeType.Comment:
                    Debug.Assert(diffgramElement.FirstChild != null);
                    Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.Comment);
                    changeInfo.Subset = diffgramElement.FirstChild.Value;
                    break;
                case XmlNodeType.ProcessingInstruction:
                    if (name == null)
                    {
                        Debug.Assert(diffgramElement.FirstChild != null);
                        Debug.Assert(diffgramElement.FirstChild.NodeType == XmlNodeType.ProcessingInstruction);
                        changeInfo.LocalName = diffgramElement.FirstChild.Name;
                        changeInfo.Subset = diffgramElement.FirstChild.Value;
                    }
                    else
                    {
                        changeInfo.LocalName = name;
                        changeInfo.Subset = ((XmlDiffViewPI)node).InnerText;
                    }
                    break;
                case XmlNodeType.EntityReference:
                    Debug.Assert(name != null);
                    changeInfo.LocalName = name;
                    break;
                case XmlNodeType.XmlDeclaration:
                    Debug.Assert(diffgramElement.FirstChild != null);
                    changeInfo.Subset = diffgramElement.InnerText;
                    break;
                case XmlNodeType.DocumentType:
                    changeInfo.LocalName = (name == null) ? ((XmlDiffViewDocumentType)node).Name : name;

                    if (diffgramElement.HasAttribute("publicId"))
                    {
                        changeInfo.Prefix = diffgramElement.GetAttribute("publicId");
                    }
                    else
                    {
                        changeInfo.Prefix = ((XmlDiffViewDocumentType)node).PublicId;
                    }

                    if (diffgramElement.HasAttribute("systemId"))
                    {
                        changeInfo.NamespaceUri = diffgramElement.GetAttribute("systemId");
                    }
                    else
                    {
                        changeInfo.NamespaceUri = ((XmlDiffViewDocumentType)node).SystemId;
                    }

                    if (diffgramElement.FirstChild != null)
                    {
                        changeInfo.Subset = diffgramElement.InnerText;
                    }
                    else
                    {
                        changeInfo.Subset = ((XmlDiffViewDocumentType)node).Subset;
                    }
                    break;
                default:
                    Debug.Assert(false, "Invalid node type.");
                    break;
            }
            node.ChangeInformation = changeInfo;
            node.Operation = XmlDiffViewOperation.Change;

            string opidAttr = diffgramElement.GetAttribute("opid");
            if (opidAttr != string.Empty) {
                node.OperationId = int.Parse(opidAttr);
            } else {
                node.OperationId = NextOperationId;
            }

            if (node.NodeType == XmlNodeType.Element &&
                diffgramElement.FirstChild != null)
            {
                this.ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)node);
            }
        }