예제 #1
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;
        }