System.Xml.XmlBaseReader.MoveToDeclaration C# (CSharp) Méthode

MoveToDeclaration() protected méthode

protected MoveToDeclaration ( ) : XmlDeclarationNode
Résultat XmlDeclarationNode
        protected XmlDeclarationNode MoveToDeclaration()
        {
            if (_attributeCount < 1)
                XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlDeclMissingVersion)));

            if (_attributeCount > 3)
                XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl)));

            // version
            if (!CheckDeclAttribute(0, "version", "1.0", false, SR.XmlInvalidVersion))
                XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlDeclMissingVersion)));

            // encoding/standalone
            // We only validate that they are the only attributes that exist.  Encoding can have any value.
            if (_attributeCount > 1)
            {
                if (CheckDeclAttribute(1, "encoding", null, true, SR.XmlInvalidEncoding))
                {
                    if (_attributeCount == 3 && !CheckStandalone(2))
                        XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl)));
                }
                else if (!CheckStandalone(1) || _attributeCount > 2)
                {
                    XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl)));
                }
            }

            if (_declarationNode == null)
            {
                _declarationNode = new XmlDeclarationNode(_bufferReader);
            }
            MoveToNode(_declarationNode);
            return _declarationNode;
        }