コード例 #1
0
ファイル: XmlDiffNode.cs プロジェクト: ca0v/XmlDiffPatch
 internal static string GetRelativeAddressOfInterval(XmlDiffNode firstNode, XmlDiffNode lastNode)
 {
     if (firstNode == lastNode)
     {
         return(firstNode.GetRelativeAddress());
     }
     return(firstNode._parent._firstChildNode == firstNode && lastNode._nextSibling == null ? "*" : firstNode.Position.ToString() + "-" + lastNode.Position.ToString());
 }
コード例 #2
0
// Methods
        internal override void WriteTo(XmlWriter xmlWriter, XmlDiff xmlDiff)
        {
            xmlWriter.WriteStartElement(XmlDiff.Prefix, "node", XmlDiff.NamespaceUri);
            xmlWriter.WriteAttributeString("match", _sourceNode.GetRelativeAddress());

            WriteChildrenTo(xmlWriter, xmlDiff);

            xmlWriter.WriteEndElement();
        }
コード例 #3
0
        internal string GetAbsoluteAddress()
        {
            string      address  = GetRelativeAddress();
            XmlDiffNode ancestor = _parent;

            while (ancestor.NodeType != XmlDiffNodeType.Document)
            {
                address  = ancestor.GetRelativeAddress() + "/" + address;
                ancestor = ancestor._parent;
            }

            return("/" + address);
        }
コード例 #4
0
// Methods
        internal override void WriteTo(XmlWriter xmlWriter, XmlDiff xmlDiff)
        {
            xmlWriter.WriteStartElement(XmlDiff.Prefix, "remove", XmlDiff.NamespaceUri);
            xmlWriter.WriteAttributeString("match", _sourceNode.GetRelativeAddress());
            if (!_bSubtree)
            {
                xmlWriter.WriteAttributeString("subtree", "no");
            }
            if (_operationID != 0)
            {
                xmlWriter.WriteAttributeString("opid", _operationID.ToString());
            }

            WriteChildrenTo(xmlWriter, xmlDiff);

            xmlWriter.WriteEndElement();
        }
コード例 #5
0
        static internal string GetRelativeAddressOfInterval(XmlDiffNode firstNode, XmlDiffNode lastNode)
        {
            Debug.Assert(firstNode._parent == lastNode._parent);

            if (firstNode == lastNode)
            {
                return(firstNode.GetRelativeAddress());
            }
            else
            {
                if (firstNode._parent._firstChildNode == firstNode &&
                    lastNode._nextSibling == null)
                {
                    return("*");
                }
                else
                {
                    return(firstNode.Position.ToString() + "-" + lastNode.Position.ToString());
                }
            }
        }
コード例 #6
0
// Methods
        internal override void WriteTo(XmlWriter xmlWriter, XmlDiff xmlDiff)
        {
            if (!_bSorted)
            {
                Sort();
            }

            xmlWriter.WriteStartElement(XmlDiff.Prefix, "remove", XmlDiff.NamespaceUri);
            if (_firstSourceNode == _lastSourceNode)
            {
                xmlWriter.WriteAttributeString("match", _firstSourceNode.GetRelativeAddress());
            }
            else
            {
                xmlWriter.WriteAttributeString("match", GetRelativeAddressOfNodeset(_firstSourceNode, _lastSourceNode));
            }
            if (_operationID != 0)
            {
                xmlWriter.WriteAttributeString("opid", _operationID.ToString());
            }
            xmlWriter.WriteEndElement();
        }
コード例 #7
0
// Methods
        internal override void WriteTo(XmlWriter xmlWriter, XmlDiff xmlDiff)
        {
            xmlWriter.WriteStartElement(XmlDiff.Prefix, "change", XmlDiff.NamespaceUri);
            xmlWriter.WriteAttributeString("match", _sourceNode.GetRelativeAddress());
            if (_operationID != 0)
            {
                xmlWriter.WriteAttributeString("opid", _operationID.ToString());
            }

            switch (_op)
            {
            case XmlDiffOperation.ChangeAttr:
            {
                XmlDiffAttribute sourceAttr = (XmlDiffAttribute)_sourceNode;
                XmlDiffAttribute targetAttr = (XmlDiffAttribute)_targetNode;

                if (sourceAttr.Prefix != targetAttr.Prefix && !xmlDiff.IgnorePrefixes && !xmlDiff.IgnoreNamespaces)
                {
                    xmlWriter.WriteAttributeString("prefix", targetAttr.Prefix);
                }
                if (sourceAttr.NamespaceURI != targetAttr.NamespaceURI && !xmlDiff.IgnoreNamespaces)
                {
                    xmlWriter.WriteAttributeString("ns", targetAttr.NamespaceURI);
                }
                xmlWriter.WriteString(targetAttr.Value);
                break;
            }

            case XmlDiffOperation.ChangeElementName:
            {
                XmlDiffElement sourceEl = (XmlDiffElement)_sourceNode;
                XmlDiffElement targetEl = (XmlDiffElement)_targetNode;

                if (sourceEl.LocalName != targetEl.LocalName)
                {
                    xmlWriter.WriteAttributeString("name", targetEl.LocalName);
                }
                if (sourceEl.Prefix != targetEl.Prefix && !xmlDiff.IgnorePrefixes && !xmlDiff.IgnoreNamespaces)
                {
                    xmlWriter.WriteAttributeString("prefix", targetEl.Prefix);
                }
                if (sourceEl.NamespaceURI != targetEl.NamespaceURI && !xmlDiff.IgnoreNamespaces)
                {
                    xmlWriter.WriteAttributeString("ns", targetEl.NamespaceURI);
                }

                WriteChildrenTo(xmlWriter, xmlDiff);

                break;
            }

            case XmlDiffOperation.ChangePI:
            {
                XmlDiffPI sourcePi = (XmlDiffPI)_sourceNode;
                XmlDiffPI targetPi = (XmlDiffPI)_targetNode;

                if (sourcePi.Value == targetPi.Value)
                {
                    Debug.Assert(sourcePi.Name != targetPi.Name);
                    xmlWriter.WriteAttributeString("name", targetPi.Name);
                }
                else
                {
                    xmlWriter.WriteProcessingInstruction(targetPi.Name, targetPi.Value);
                }
                break;
            }

            case XmlDiffOperation.ChangeCharacterData:
            {
                XmlDiffCharData chd = (XmlDiffCharData)_targetNode;
                switch (_targetNode.NodeType)
                {
                case XmlDiffNodeType.Text:
                case XmlDiffNodeType.SignificantWhitespace:
                    xmlWriter.WriteString(chd.Value);
                    break;

                case XmlDiffNodeType.Comment:
                    xmlWriter.WriteComment(chd.Value);
                    break;

                case XmlDiffNodeType.CDATA:
                    xmlWriter.WriteCData(chd.Value);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
                break;
            }

            case XmlDiffOperation.ChangeER:
            {
                xmlWriter.WriteAttributeString("name", ((XmlDiffER)_targetNode).Name);
                break;
            }

            case XmlDiffOperation.ChangeXmlDeclaration:
            {
                xmlWriter.WriteString(((XmlDiffXmlDeclaration)_targetNode).Value);
                break;
            }

            case XmlDiffOperation.ChangeDTD:
            {
                XmlDiffDocumentType sourceDtd = (XmlDiffDocumentType)_sourceNode;
                XmlDiffDocumentType targetDtd = (XmlDiffDocumentType)_targetNode;

                if (sourceDtd.Name != targetDtd.Name)
                {
                    xmlWriter.WriteAttributeString("name", targetDtd.Name);
                }
                if (sourceDtd.SystemId != targetDtd.SystemId)
                {
                    xmlWriter.WriteAttributeString("systemId", targetDtd.SystemId);
                }
                if (sourceDtd.PublicId != targetDtd.PublicId)
                {
                    xmlWriter.WriteAttributeString("publicId", targetDtd.PublicId);
                }
                if (sourceDtd.Subset != targetDtd.Subset)
                {
                    xmlWriter.WriteCData(targetDtd.Subset);
                }
                break;
            }

            default:
                Debug.Assert(false);
                break;
            }

            xmlWriter.WriteEndElement();
        }
コード例 #8
0
ファイル: XmlDiffNodes.cs プロジェクト: Podracer/DAE-notepad
        internal static string GetRelativeAddressOfInterval( XmlDiffNode firstNode, XmlDiffNode lastNode )
        {
            Debug.Assert( firstNode._parent == lastNode._parent );

            if ( firstNode == lastNode )
            return firstNode.GetRelativeAddress();
            else
            {
            if ( firstNode._parent._firstChildNode == firstNode &&
                 lastNode._nextSibling == null )
                return "*";
            else
                return firstNode.Position.ToString() + "-" + lastNode.Position.ToString();
            }
        }