示例#1
0
        internal override XmlDiffViewNode Clone(bool bDeep)
        {
            var xmlDiffViewElement = new XmlDiffViewElement(this._localName, this._prefix, this._ns, this._ignorePrefixes);
            var diffViewAttribute  = this._attributes;
            var refAttr            = (XmlDiffViewAttribute)null;

            for (; diffViewAttribute != null; diffViewAttribute = (XmlDiffViewAttribute)diffViewAttribute._nextSibbling)
            {
                var newAttr = (XmlDiffViewAttribute)diffViewAttribute.Clone(true);
                xmlDiffViewElement.InsertAttributeAfter(newAttr, refAttr);
                refAttr = newAttr;
            }
            if (!bDeep)
            {
                return((XmlDiffViewNode)xmlDiffViewElement);
            }
            var xmlDiffViewNode = this._childNodes;
            var referenceChild  = (XmlDiffViewNode)null;

            for (; xmlDiffViewNode != null; xmlDiffViewNode = xmlDiffViewNode._nextSibbling)
            {
                var newChild = xmlDiffViewNode.Clone(true);
                xmlDiffViewElement.InsertChildAfter(newChild, referenceChild, false);
                referenceChild = newChild;
            }
            return((XmlDiffViewNode)xmlDiffViewElement);
        }
示例#2
0
 /// <summary>
 /// Gets a list of the attributes for the specifed node
 /// and if applicable, its children.
 /// </summary>
 /// <param name="parentElement">The node which
 /// contains the attributes</param>
 /// <returns>List of attributes</returns>
 private static XmlDiffPathNodeList SelectAllAttributes(
     XmlDiffViewElement parentElement)
 {
     if (parentElement.Attributes == null)
     {
         OnNoMatchingNode("@*");
         return(null);
     }
     else if (parentElement.Attributes.NextSibling == null)
     {
         XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
         nodeList.AddNode(parentElement.Attributes);
         return(nodeList);
     }
     else
     {
         XmlDiffPathNodeList  nodeList = new XmlDiffPathMultiNodeList();
         XmlDiffViewAttribute curAttr  = parentElement.Attributes;
         while (curAttr != null)
         {
             nodeList.AddNode(curAttr);
         }
         return(nodeList);
     }
 }
示例#3
0
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode newNode = null;

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

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

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

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

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

            int pos = 1;
            XmlDiffPathNodeList nodeList = null;

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

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

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

                nodeList.AddNode(attr);

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

            return(nodeList);
        }
示例#5
0
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode xmlDiffViewNode = null;

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

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

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

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

            default:
                Debug.Assert(false, "Invalid node type.");
                break;
            }
            Debug.Assert(xmlDiffViewNode != null);
            return(xmlDiffViewNode);
        }
示例#6
0
        private static XmlDiffPathNodeList SelectAttributes(
            XmlDiffViewElement parentElement,
            string path)
        {
            Debug.Assert(path[0] == '@');
            var pos = 1;
            var diffPathNodeList = (XmlDiffPathNodeList)null;

            while (true)
            {
                var name = XmlDiffPath.ReadAttrName(path, ref pos);
                if (diffPathNodeList == null)
                {
                    diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                }
                var attribute = parentElement.GetAttribute(name);
                if (attribute == null)
                {
                    XmlDiffPath.OnNoMatchingNode(path);
                }
                diffPathNodeList.AddNode((XmlDiffViewNode)attribute);
                if (pos != path.Length)
                {
                    if (path[pos] == '|')
                    {
                        var index = pos + 1;
                        if (path[index] != '@')
                        {
                            XmlDiffPath.OnInvalidExpression(path);
                        }
                        pos = index + 1;
                    }
                    else
                    {
                        XmlDiffPath.OnInvalidExpression(path);
                    }
                }
                else
                {
                    break;
                }
            }
            return(diffPathNodeList);
        }
示例#7
0
        /// <summary>
        /// Creates a complete copy of the current node.
        /// </summary>
        /// <param name="deep">has child nodes</param>
        /// <returns>A copy of the current node</returns>
        internal override XmlDiffViewNode Clone(bool deep)
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement(
                this.LocalName,
                this.Prefix,
                this.NamespaceUri,
                this.ignorePrefixes);

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

                    curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
                }
            }

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

                    curChild = curChild.NextSibbling;
                }
            }

            return(newElement);
        }
        internal override XmlDiffViewNode Clone(bool bDeep)
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement(_localName, _prefix, _ns, _ignorePrefixes);

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

                    curAttr = (XmlDiffViewAttribute)curAttr._nextSibbling;
                }
            }

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

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

                    curChild = curChild._nextSibbling;
                }
            }

            return(newElement);
        }
示例#9
0
        private static XmlDiffPathNodeList SelectAllAttributes(
            XmlDiffViewElement parentElement)
        {
            if (parentElement._attributes == null)
            {
                XmlDiffPath.OnNoMatchingNode("@*");
                return((XmlDiffPathNodeList)null);
            }
            if (parentElement._attributes._nextSibbling == null)
            {
                var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList();
                diffPathNodeList.AddNode((XmlDiffViewNode)parentElement._attributes);
                return(diffPathNodeList);
            }
            var diffPathNodeList1 = (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList();
            var attributes        = parentElement._attributes;

            while (attributes != null)
            {
                diffPathNodeList1.AddNode((XmlDiffViewNode)attributes);
            }
            return(diffPathNodeList1);
        }
        internal override XmlDiffViewNode Clone( bool bDeep )
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement( _localName, _prefix, _ns, _ignorePrefixes );

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

                curAttr = (XmlDiffViewAttribute)curAttr._nextSibbling;
            }
            }

            if ( !bDeep )
            return newElement;

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

                curChild = curChild._nextSibbling;
            }
            }

            return newElement;
        }
示例#11
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;
            }
        }
示例#12
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>
        /// Generate a new node
        /// </summary>
        /// <param name="node">node to clone</param>
        /// <returns>the new node</returns>
        private XmlDiffViewNode ImportNode(XmlNode node)
        {
            XmlDiffViewNode newNode = null;
            switch (node.NodeType)
            {
                case XmlNodeType.Element:
                    XmlElement el = (XmlElement)node;
                    XmlDiffViewElement newElement = new XmlDiffViewElement(
                        el.LocalName,
                        el.Prefix,
                        el.NamespaceURI,
                        this.ignorePrefixes);

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

                    // children
                    IEnumerator childNodes = node.ChildNodes.GetEnumerator();
                    XmlDiffViewNode lastNewChildNode = null;
                    while (childNodes.MoveNext())
                    {
                        XmlDiffViewNode newChildNode = this.ImportNode(
                            (XmlNode)childNodes.Current);
                        newElement.InsertChildAfter(
                            newChildNode,
                            lastNewChildNode,
                            false);
                        lastNewChildNode = newChildNode;
                    }
                    newNode = newElement;
                    break;
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                    newNode = new XmlDiffViewCharData(
                        node.Value,
                        node.NodeType);
                    break;
                case XmlNodeType.ProcessingInstruction:
                    newNode = new XmlDiffViewPI(node.Name, node.Value);
                    break;
                case XmlNodeType.EntityReference:
                    Debug.Assert(false, "XmlDiffViewER was thought to be dead code");
                    //// newNode = new XmlDiffViewER(node.Name);
                    break;
                default:
                    Debug.Assert(false, "Invalid node type.");
                    break;
            }
            Debug.Assert(newNode != null);
            return newNode;
        }
示例#14
0
        /// <summary>
        /// Gets a list of attribute objects based on the location
        /// specified.
        /// </summary>
        /// <param name="parentElement">Node at which to start the path search</param>
        /// <param name="path">Proprietary alphanumeric path statement</param>
        /// <returns>list of attribute objects</returns>
        private static XmlDiffPathNodeList SelectAttributes(
            XmlDiffViewElement parentElement,
            string path) {
            Debug.Assert(path[0] == '@');

            int pos = 1;
            XmlDiffPathNodeList nodeList = null;
            for (; ; ) {
                string name = ReadAttrName(path, ref pos);

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

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

                if (pos == path.Length) {
                    break;
                } else if (path[pos] == '|') {
                    pos++;
                    if (path[pos] != '@') {
                        OnInvalidExpression(path);
                    }
                    pos++;
                } else {
                    OnInvalidExpression(path);
                }
            }
            return nodeList;
        }
示例#15
0
 /// <summary>
 /// Gets a list of the attributes for the specifed node
 /// and if applicable, its children.
 /// </summary>
 /// <param name="parentElement">The node which 
 /// contains the attributes</param>
 /// <returns>List of attributes</returns>
 private static XmlDiffPathNodeList SelectAllAttributes(
     XmlDiffViewElement parentElement) {
     if (parentElement.Attributes == null) {
         OnNoMatchingNode("@*");
         return null;
     } else if (parentElement.Attributes.NextSibbling == null) {
         XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
         nodeList.AddNode(parentElement.Attributes);
         return nodeList;
     } else {
         XmlDiffPathNodeList nodeList = new XmlDiffPathMultiNodeList();
         XmlDiffViewAttribute curAttr = parentElement.Attributes;
         while (curAttr != null) {
             nodeList.AddNode(curAttr);
         }
         return nodeList;
     }
 }
示例#16
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;
        }
示例#17
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>
        /// 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;
        }
        /// <summary>
        /// Creates a complete copy of the current node.
        /// </summary>
        /// <param name="deep">has child nodes</param>
        /// <returns>A copy of the current node</returns>
        internal override XmlDiffViewNode Clone(bool deep)
        {
            XmlDiffViewElement newElement = new XmlDiffViewElement(
                this.LocalName, 
                this.Prefix, 
                this.NamespaceUri, 
                this.ignorePrefixes);

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

                    curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
                }
            }

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

                    curChild = curChild.NextSibbling;
                }
            }

            return newElement;
        }
        /// <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;
            }
        }