Beispiel #1
0
        private bool GenEntity(XmlQualifiedName qname)
        {
            string n = qname.Name;

            if (n[0] == '#')   // char entity reference
            {
                return(false);
            }
            else if (SchemaEntity.IsPredefinedEntity(n))
            {
                return(false);
            }
            else
            {
                SchemaEntity en = GetEntity(qname, false);
                if (en == null)
                {
                    // well-formness error, see xml spec [68]
                    throw new XmlException(Res.Xml_UndeclaredEntity, n);
                }
                if (!en.NData.IsEmpty)
                {
                    // well-formness error, see xml spec [68]
                    throw new XmlException(Res.Xml_UnparsedEntityRef, n);
                }

                if (reader.StandAlone && en.DeclaredInExternal)
                {
                    SendValidationEvent(Res.Sch_StandAlone);
                }
                return(true);
            }
        }
        protected static void ProcessEntity(SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition)
        {
            SchemaEntity       en = (SchemaEntity)sinfo.GeneralEntities[new XmlQualifiedName(name)];
            XmlSchemaException e  = null;

            if (en == null)
            {
                // validation error, see xml spec [68]
                e = new XmlSchemaException(Res.Sch_UndeclaredEntity, name, baseUri, lineNumber, linePosition);
            }
            else if (en.NData.IsEmpty)
            {
                e = new XmlSchemaException(Res.Sch_UnparsedEntityRef, name, baseUri, lineNumber, linePosition);
            }
            if (e != null)
            {
                if (eventhandler != null)
                {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else
                {
                    throw e;
                }
            }
        }
        private bool GenEntity(XmlQualifiedName qname)
        {
            string name = qname.Name;

            if (name[0] == '#')
            {
                return(false);
            }
            if (SchemaEntity.IsPredefinedEntity(name))
            {
                return(false);
            }
            SchemaEntity entity = this.GetEntity(qname, false);

            if (entity == null)
            {
                throw new XmlException("Xml_UndeclaredEntity", name);
            }
            if (!entity.NData.IsEmpty)
            {
                throw new XmlException("Xml_UnparsedEntityRef", name);
            }
            if (base.reader.StandAlone && entity.DeclaredInExternal)
            {
                base.SendValidationEvent("Sch_StandAlone");
            }
            return(true);
        }
Beispiel #4
0
        // returns true == continue parsing
        // return false == unexpanded external entity, stop parsing and return
        private EntityType HandleGeneralEntityReference( string name, bool isInAttributeValue, bool pushFakeEntityIfNullResolver, int entityStartLinePos ) {
            IDtdEntityInfo entity = null;

            if ( dtdInfo == null && fragmentParserContext != null && fragmentParserContext.HasDtdInfo && dtdProcessing == DtdProcessing.Parse ) {
                ParseDtdFromParserContext();
            }

            if ( dtdInfo == null || 
                 ( ( entity = dtdInfo.LookupEntity( name) ) == null ) ) {
#if !SILVERLIGHT // Needed only for XmlTextReader (when used from XmlDocument)
                if ( disableUndeclaredEntityCheck ) {
                    SchemaEntity schemaEntity = new SchemaEntity( new XmlQualifiedName( name ), false );
                    schemaEntity.Text = string.Empty;
                    entity = schemaEntity;
                }
                else
#endif
                Throw( Res.Xml_UndeclaredEntity, name, ps.LineNo, entityStartLinePos );
            }

            if ( entity.IsUnparsedEntity ) {
#if !SILVERLIGHT // Needed only for XmlTextReader (when used from XmlDocument)
                if ( disableUndeclaredEntityCheck ) {
                    SchemaEntity schemaEntity = new SchemaEntity( new XmlQualifiedName( name ), false );
                    schemaEntity.Text = string.Empty;
                    entity = schemaEntity;
                }
                else
#endif
                Throw( Res.Xml_UnparsedEntityRef, name, ps.LineNo, entityStartLinePos ); 
            }

            if ( standalone && entity.IsDeclaredInExternal ) {
                Throw( Res.Xml_ExternalEntityInStandAloneDocument, entity.Name, ps.LineNo, entityStartLinePos );
            }

            if ( entity.IsExternal ) {
                if ( isInAttributeValue ) {
                    Throw( Res.Xml_ExternalEntityInAttValue, name, ps.LineNo, entityStartLinePos );
                    return EntityType.Skipped;
                }

                if ( parsingMode == ParsingMode.SkipContent ) {
                    return EntityType.Skipped;
                }

                if (IsResolverNull) {
                    if ( pushFakeEntityIfNullResolver ) {
                        PushExternalEntity( entity );
                        curNode.entityId = ps.entityId;
                        return EntityType.FakeExpanded;
                    }
                    return EntityType.Skipped;
                }
                else {
                    PushExternalEntity( entity );
                    curNode.entityId = ps.entityId;
#if SILVERLIGHT // Needed only for XmlTextReader (reporting of entities)
                    return EntityType.Expanded; 
#else
                    return (isInAttributeValue && validatingReaderCompatFlag) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
#endif
                }
            }
            else {
                if ( parsingMode == ParsingMode.SkipContent ) {
                    return EntityType.Skipped;
                }

                PushInternalEntity( entity );

                curNode.entityId = ps.entityId;
#if SILVERLIGHT // Needed only for XmlTextReader (reporting of entities)
                return EntityType.Expanded;
#else
                return ( isInAttributeValue && validatingReaderCompatFlag ) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
#endif
            }
        }
        private void ParseEntityDecl() {
            bool isParamEntity = false;
            SchemaEntity entity = null;

            // get entity name and type
            switch ( GetToken( true ) ) {
                case Token.Percent:
                    isParamEntity = true;
                    if ( GetToken( true ) != Token.Name ) {
                        goto UnexpectedError;
                    }
                    goto case Token.Name;
                case Token.Name:
                    // create entity object
                    XmlQualifiedName entityName = GetNameQualified( false );
                    entity = new SchemaEntity( entityName, isParamEntity );
                    
                    entity.BaseURI = BaseUriStr;
                    entity.DeclaredURI = ( externalDtdBaseUri.Length == 0 ) ? documentBaseUri : externalDtdBaseUri;

                    if ( isParamEntity ) {
                        if ( schemaInfo.ParameterEntities[ entityName ] == null ) {
                            schemaInfo.ParameterEntities.Add( entityName, entity );
                        }
                    }
                    else {
                        if ( schemaInfo.GeneralEntities[ entityName ] == null ) {
                            schemaInfo.GeneralEntities.Add( entityName, entity );
                        }
                    }
                    entity.DeclaredInExternal = !ParsingInternalSubset;
                    entity.IsProcessed = true;
                    break;
                default:
                    goto UnexpectedError;
            }

            Token token = GetToken( true );
            switch ( token ) {
                case Token.PUBLIC:
                case Token.SYSTEM:
                    string systemId;
                    string publicId;
                    ParseExternalId( token, Token.EntityDecl, out publicId, out systemId );
                    entity.IsExternal = true;
                    entity.Url = systemId;
                    entity.Pubid = publicId;

                    if ( GetToken( false ) == Token.NData ) {
                        if ( isParamEntity ) {
                            ThrowUnexpectedToken( curPos - 5, ">" ); // 5 == strlen("NDATA")
                        }
                        if ( !whitespaceSeen ) { 
                            Throw( curPos - 5, Res.Xml_ExpectingWhiteSpace, "NDATA" );
                        }

                        if ( GetToken( true ) != Token.Name ) {
                            goto UnexpectedError;
                        }
                        
                        entity.NData = GetNameQualified( false );
                        string notationName = entity.NData.Name;
                        if ( schemaInfo.Notations[ notationName ] == null ) {
                            if ( undeclaredNotations == null ) {
                                undeclaredNotations = new Hashtable();
                            }
                            UndeclaredNotation un = new UndeclaredNotation( notationName, LineNo, LinePos - notationName.Length );
                            UndeclaredNotation loggedUn = (UndeclaredNotation)undeclaredNotations[notationName];
                            if ( loggedUn != null ) {
                                un.next = loggedUn.next;
                                loggedUn.next = un;
                            }
                            else {
                                undeclaredNotations.Add( notationName, un );
                            }
                        }
                    }
                    break;
                case Token.Literal:
                    entity.Text = GetValue();
                    entity.Line = (int)literalLineInfo.lineNo;
                    entity.Pos = (int)literalLineInfo.linePos;
                    break;
                default:
                    goto UnexpectedError;
            }

            if ( GetToken( false ) == Token.GreaterThan ) {
                entity.IsProcessed = false;
                return;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
        private void PushInternalEntity( SchemaEntity entity, int entityId ) {
            Debug.Assert( !entity.IsExternal );

            Encoding enc = ps.encoding;

            PushParsingState();

            InitStringInput( ( entity.DeclaredURI != null ) ? entity.DeclaredURI : string.Empty, enc, entity.Text );

            ps.entity = entity;
            ps.entityId = entityId;
            ps.lineNo = entity.Line;
            ps.lineStartPos = - entity.Pos - 1;

            ps.eolNormalized = true;
            entity.IsProcessed = true;
        }
        // returns true if real entity has been pushed, false if fake entity (=empty content entity)
        private bool PushExternalEntity( SchemaEntity entity, int entityId ) {
            Debug.Assert( entity.IsExternal );

            if ( xmlResolver != null ) {

                Uri entityBaseUri = ( entity.BaseURI.Length > 0 ) ? xmlResolver.ResolveUri( null, entity.BaseURI ): null;
                Uri entityUri = xmlResolver.ResolveUri( entityBaseUri, entity.Url );
                Stream stream = null;
                try {
                    stream = OpenStream( entityUri );
                }
                catch ( Exception e ) {
                    if ( v1Compat ) {
                        throw;
                    }
                    Throw( new XmlException( Res.Xml_ErrorOpeningExternalEntity, new string[] { entityUri.ToString(), e.Message }, e, 0, 0 ) );
                }

                if ( stream == null ) {
                    Throw( Res.Xml_CannotResolveEntity, entity.Name.Name );
                }

                PushParsingState();

                if ( v1Compat ) {
                    InitStreamInput( entityUri, stream, null );
                }
                else {
                    InitStreamInput( entityUri, stream, null );
                }

                ps.entity = entity;
                ps.entityId = entityId;
                entity.IsProcessed = true;

                Debug.Assert( ps.appendMode );
                int initialPos = ps.charPos;
                if ( v1Compat ) {
                    EatWhitespaces( null );
                }
                if ( !ParseXmlDeclaration( true ) ) {
                    ps.charPos = initialPos;
                }
                return true;
            }
            else {
                Encoding enc = ps.encoding;

                PushParsingState();
                InitStringInput( entity.Url, enc, string.Empty );

                ps.entity = entity;
                ps.entityId = entityId;

                return false;
            }
        }
        // return true if EndEntity node should be reported. The entity is stored in lastEntity.
        private bool HandleEntityEnd( bool checkEntityNesting ) {
            if ( parsingStatesStackTop == -1 ) {
                Debug.Assert( false );
                Throw( Res.Xml_InternalError );
            }

            if ( ps.entityResolvedManually ) {
                index--;

                if ( checkEntityNesting ) {
                    if ( ps.entityId != nodes[index].entityId ) {
                        Throw( Res.Xml_IncompleteEntity );
                    }
                }

                lastEntity = ps.entity;  // save last entity for the EndEntity node

                PopEntity();
                curNode.entityId = ps.entityId;
                return true;
            }
            else {
                if ( checkEntityNesting ) {
                    if ( ps.entityId != nodes[index].entityId ) {
                        Throw( Res.Xml_IncompleteEntity );
                    }
                }

                PopEntity();
                curNode.entityId = ps.entityId;

                reportedEncoding = ps.encoding;
                reportedBaseUri = ps.baseUriStr;
                return false;
            }
        }
Beispiel #9
0
        private    void PushScanner(XmlScanner scanner, SchemaEntity en, Uri baseUrl) {
            DtdScannerState s;

            if (en != null && _L >= 0 && _HasTerminal) {
                SendValidationEvent(Res.Sch_ParEntityRefNesting, null);
            }

            s = (DtdScannerState)_ScannerStack.Push();
            if (s == null) {
                s = new DtdScannerState();
                _ScannerStack[_ScannerStack.Length-1] = s;
            }
            s._Scanner = _Scanner;
            s._En = en;
            s._IsInternal = _IsInternal;
            s._L = _L;
            s._IncludeDepth = _IncludeDepth;
            s._IgnoreDepth = _IgnoreDepth;
            s._BaseUri = _BaseUri;
            _Scanner = scanner;
            _Scanner.InDTD = true;
            _BaseUri = baseUrl;
            if (en != null) {
                _HasSeenWhiteSpace = en.IsParEntity;
                en.IsProcessed = true;
                if (_IsInternal)
                    _IsInternal = !en.IsExternal;
                _HasSeenContent = !en.IsExternal;
            }
        }
 internal bool DtdParserProxy_PopEntity( out SchemaEntity oldEntity, out int newEntityId ) {
     if ( parsingStatesStackTop == -1 ) {
         oldEntity = null;
         newEntityId = -1;
         return false;
     }
     oldEntity = ps.entity;
     PopEntity();
     newEntityId = ps.entityId;
     return true;
 }
 internal bool DtdParserProxy_PushEntity( SchemaEntity entity, int entityId ) {
     if ( entity.IsExternal ) {
         if ( xmlResolver == null ) {
             return false;
         }
         return PushExternalEntity( entity, entityId );
     }
     else {
         PushInternalEntity( entity, entityId );
         return true;
     }
 }
 bool IDtdParserAdapter.PopEntity( out SchemaEntity oldEntity, out int newEntityId ) { 
     return reader.DtdParserProxy_PopEntity( out oldEntity, out newEntityId ); 
 }
 bool IDtdParserAdapter.PushEntity( SchemaEntity entity, int entityId ) { 
     return reader.DtdParserProxy_PushEntity( entity, entityId ); 
 }
Beispiel #14
0
        private    void PushAttValueScanner(XmlScanner scanner, SchemaEntity en) {
            if (_AttValueScannerStack == null) {
                _AttValueScannerStack = new HWStack(STACK_INCREMENT);
            }

            DtdScannerState s = (DtdScannerState)_AttValueScannerStack.Push();
            if (s == null) {
                s = new DtdScannerState();
                _AttValueScannerStack[_AttValueScannerStack.Length-1] = s;
            }
            s._Scanner = _Scanner;
            s._En = en;
            en.IsProcessed = true;
        }
Beispiel #15
0
        // returns true == continue parsing
        // return false == unexpanded external entity, stop parsing and return
        private EntityType HandleGeneralEntityReference(string name, bool isInAttributeValue, bool pushFakeEntityIfNullResolver, int entityStartLinePos)
        {
            IDtdEntityInfo entity = null;

            if (_dtdInfo == null && _fragmentParserContext != null && _fragmentParserContext.HasDtdInfo && _dtdProcessing == DtdProcessing.Parse)
            {
                ParseDtdFromParserContext();
            }

            if (_dtdInfo == null ||
                 ((entity = _dtdInfo.LookupEntity(name)) == null))
            {
                if (_disableUndeclaredEntityCheck)
                {
                    SchemaEntity schemaEntity = new SchemaEntity(new XmlQualifiedName(name), false);
                    schemaEntity.Text = string.Empty;
                    entity = schemaEntity;
                }
                else
                    Throw(SR.Xml_UndeclaredEntity, name, _ps.LineNo, entityStartLinePos);
            }

            if (entity.IsUnparsedEntity)
            {
                if (_disableUndeclaredEntityCheck)
                {
                    SchemaEntity schemaEntity = new SchemaEntity(new XmlQualifiedName(name), false);
                    schemaEntity.Text = string.Empty;
                    entity = schemaEntity;
                }
                else
                    Throw(SR.Xml_UnparsedEntityRef, name, _ps.LineNo, entityStartLinePos);
            }

            if (_standalone && entity.IsDeclaredInExternal)
            {
                Throw(SR.Xml_ExternalEntityInStandAloneDocument, entity.Name, _ps.LineNo, entityStartLinePos);
            }

            if (entity.IsExternal)
            {
                if (isInAttributeValue)
                {
                    Throw(SR.Xml_ExternalEntityInAttValue, name, _ps.LineNo, entityStartLinePos);
                    return EntityType.Skipped;
                }

                if (_parsingMode == ParsingMode.SkipContent)
                {
                    return EntityType.Skipped;
                }

                if (IsResolverNull)
                {
                    if (pushFakeEntityIfNullResolver)
                    {
                        PushExternalEntity(entity);
                        _curNode.entityId = _ps.entityId;
                        return EntityType.FakeExpanded;
                    }
                    return EntityType.Skipped;
                }
                else
                {
                    PushExternalEntity(entity);
                    _curNode.entityId = _ps.entityId;
                    return (isInAttributeValue && _validatingReaderCompatFlag) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
                }
            }
            else
            {
                if (_parsingMode == ParsingMode.SkipContent)
                {
                    return EntityType.Skipped;
                }

                PushInternalEntity(entity);

                _curNode.entityId = _ps.entityId;
                return (isInAttributeValue && _validatingReaderCompatFlag) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
            }
        }
        // returns true == continue parsing
        // return false == unexpanded external entity, stop parsing and return
        private EntityType HandleGeneralEntityReference( string name, bool isInAttributeValue, bool pushFakeEntityIfNullResolver, int entityStartLinePos ) {
            SchemaEntity entity = null;
            XmlQualifiedName qName = new XmlQualifiedName( name );

            if ( dtdParserProxy == null && fragmentParserContext != null && fragmentParserContext.HasDtdInfo && !prohibitDtd ) {
                ParseDtdFromParserContext();
            }

            if ( dtdParserProxy == null || 
                 ( ( entity = (SchemaEntity) dtdParserProxy.DtdSchemaInfo.GeneralEntities[qName] ) == null ) ) { 
                if ( disableUndeclaredEntityCheck ) {
                    entity = new SchemaEntity( new XmlQualifiedName( name ), false );
                    entity.Text = string.Empty;
                }
                else {
                    Throw( Res.Xml_UndeclaredEntity, name, ps.LineNo, entityStartLinePos );
                }
            }

            if ( entity.IsProcessed ) {
                Throw( Res.Xml_RecursiveGenEntity, name, ps.LineNo, entityStartLinePos );
            }

            if ( !entity.NData.IsEmpty ) {
                if ( disableUndeclaredEntityCheck ) {
                    entity = new SchemaEntity( new XmlQualifiedName( name ), false );
                    entity.Text = string.Empty;
                }
                else {
                    Throw( Res.Xml_UnparsedEntityRef, name, ps.LineNo, entityStartLinePos ); 
                }
            }

            if ( standalone && entity.DeclaredInExternal ) {
                Throw( Res.Xml_ExternalEntityInStandAloneDocument, entity.Name.Name, ps.LineNo, entityStartLinePos );
            }

            if ( entity.IsExternal ) {
                if ( isInAttributeValue ) {
                    Throw( Res.Xml_ExternalEntityInAttValue, name, ps.LineNo, entityStartLinePos );
                    return EntityType.Skipped;
                }

                if ( parsingMode == ParsingMode.SkipContent ) {
                    return EntityType.Skipped;
                }

                if ( xmlResolver == null ) {
                    if ( pushFakeEntityIfNullResolver ) {
                        PushExternalEntity( entity, ++nextEntityId );
                        curNode.entityId = ps.entityId;
                        return EntityType.FakeExpanded;
                    }
                    return EntityType.Skipped;
                }
                else {
                    PushExternalEntity( entity, ++nextEntityId );
                    curNode.entityId = ps.entityId;
                    return ( isInAttributeValue && validatingReaderCompatFlag ) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
                }
            }
            else {
                if ( parsingMode == ParsingMode.SkipContent ) {
                    return EntityType.Skipped;
                }

                int entityId = nextEntityId++;
                PushInternalEntity( entity, entityId );

                curNode.entityId = entityId;
                return ( isInAttributeValue && validatingReaderCompatFlag ) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
            }
        }
Beispiel #17
0
        private void ParseEntityDecl()
        {
            bool isParamEntity = false;
            SchemaEntity entity = null;

            // get entity name and type
            switch (GetToken(true))
            {
                case Token.Percent:
                    isParamEntity = true;
                    if (GetToken(true) != Token.Name)
                    {
                        goto UnexpectedError;
                    }
                    goto case Token.Name;
                case Token.Name:
                    // create entity object
                    XmlQualifiedName entityName = GetNameQualified(false);
                    entity = new SchemaEntity(entityName, isParamEntity);

                    entity.BaseURI = BaseUriStr;
                    entity.DeclaredURI = (_externalDtdBaseUri.Length == 0) ? _documentBaseUri : _externalDtdBaseUri;

                    if (isParamEntity)
                    {
                        if (!_schemaInfo.ParameterEntities.ContainsKey(entityName))
                        {
                            _schemaInfo.ParameterEntities.Add(entityName, entity);
                        }
                    }
                    else
                    {
                        if (!_schemaInfo.GeneralEntities.ContainsKey(entityName))
                        {
                            _schemaInfo.GeneralEntities.Add(entityName, entity);
                        }
                    }
                    entity.DeclaredInExternal = !ParsingInternalSubset;
                    entity.ParsingInProgress = true;
                    break;
                default:
                    goto UnexpectedError;
            }

            Token token = GetToken(true);
            switch (token)
            {
                case Token.PUBLIC:
                case Token.SYSTEM:
                    string systemId;
                    string publicId;

                    ParseExternalId(token, Token.EntityDecl, out publicId, out systemId);

                    entity.IsExternal = true;
                    entity.Url = systemId;
                    entity.Pubid = publicId;

                    if (GetToken(false) == Token.NData)
                    {
                        if (isParamEntity)
                        {
                            ThrowUnexpectedToken(_curPos - 5, ">"); // 5 == strlen("NDATA")
                        }
                        if (!_whitespaceSeen)
                        {
                            Throw(_curPos - 5, SR.Xml_ExpectingWhiteSpace, "NDATA");
                        }

                        if (GetToken(true) != Token.Name)
                        {
                            goto UnexpectedError;
                        }

                        entity.NData = GetNameQualified(false);
#if !SILVERLIGHT
                        string notationName = entity.NData.Name;
                        if (!_schemaInfo.Notations.ContainsKey(notationName))
                        {
                            AddUndeclaredNotation(notationName);
                        }
#endif
                    }
                    break;
                case Token.Literal:
                    entity.Text = GetValue();
                    entity.Line = (int)_literalLineInfo.lineNo;
                    entity.Pos = (int)_literalLineInfo.linePos;
                    break;
                default:
                    goto UnexpectedError;
            }

            if (GetToken(false) == Token.GreaterThan)
            {
                entity.ParsingInProgress = false;
                return;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
Beispiel #18
0
        private     void ParseEntity() {
            while (true) {
                switch (_SubState) {
                    case 0:
                        SkipWhitespace(true);
                        _SubState = 1;
                        break;

                    case 1:
                        GetToken();
                        if (_Token == XmlToken.PERCENT) {
                            _IsParEntity = true;
                            _SubState = 2;
                        }
                        else {
                            _IsParEntity = false;
                            _SubState = 4;
                        }
                        break;

                    case 2:
                        SkipWhitespace(true);
                        _SubState = 3;
                        break;

                    case 3:
                        GetToken();
                        _SubState = 4;
                        break;

                    case 4:
                        _Entity = new SchemaEntity(GetName(_Token, false), _IsParEntity);
                        if (_BaseUri != null) {
                            _Entity.BaseURI = XmlUrlResolver.UnEscape(_BaseUri.ToString());
                        }
                        if (_IsLoadingExternalDTD) {
                            _Entity.DeclaredURI = _ExternalDTDBaseUri;
                        } else {
                            _Entity.DeclaredURI = _DocBaseUri;
                        }

                        if (_Entity.IsParEntity) {
                            if (_SchemaInfo.ParameterEntities[_Entity.Name] == null) {
                                _SchemaInfo.ParameterEntities.Add(_Entity.Name, _Entity);
                            }
                        }
                        else {
                            if (_SchemaInfo.GeneralEntities[_Entity.Name] == null) {
                                _SchemaInfo.GeneralEntities.Add(_Entity.Name, _Entity);
                            }
                        }
                        _Entity.DeclaredInExternal = !_IsInternal;
                        _Entity.IsProcessed = true;
                        _SubState = 5;
                        break;

                    case 5:
                        GetToken();
                        if (_Token == XmlToken.QUOTE) { // EntityValue
                            //grab line number position for entity value
                            _Entity.Line = _Scanner.LineNum;
                            _Entity.Pos = _Scanner.LinePos - 1;

                            _SubState = 6;
                            Push(DtdFunctionIndex.GetEntityValue);
                            GetEntityValue();
                        }
                        else {
                            _SubState = 7;
                            Push(DtdFunctionIndex.ParseExternalID);
                            ParseExternalID();
                        }
                        break;

                    case 6:
                        GetToken();
                        _SubState = 11;
                        break;

                    case 7:
                        if (_HasExternalID) {
                            _SubState = 8;
                            _HasSeenWhiteSpace = SkipWhitespace(false);
                        }
                        else {
                            throw new XmlException(Res.Xml_ExpectExternalIdOrEntityValue, _Scanner.StartLineNum, _Scanner.StartLinePos);
                        }
                        break;

                    case 8:
                        GetToken();
                        _Entity.IsExternal = true;
                        _Entity.Url = _SystemLiteral;
                        _Entity.Pubid = _PubidLiteral;

                        if (!_IsParEntity && _Token == XmlToken.NAME && _Scanner.IsToken(XmlToken.NDATA)) {
                            if (!_HasSeenWhiteSpace)
                                throw new XmlException(Res.Xml_UnexpectedToken, XmlToken.ToString(XmlToken.WHITESPACE), _Scanner.StartLineNum, _Scanner.StartLinePos);

                            _SubState = 9;
                        }
                        else {
                            _SubState = 11;
                        }
                        break;

                    case 9:
                        GetToken(XmlToken.NAME);
                        _Entity.NData = GetName(XmlToken.NAME, false);
                        if (_SchemaInfo.Notations[_Entity.NData.Name] == null) {
                            _SchemaInfo.AddForwardRef(_Entity.NData.Name, _Entity.NData.Namespace, _Entity.NData.Name,
                                                      _Scanner.LineNum, _Scanner.LinePos,
                                                      false, ForwardRef.Type.NOTATION);
                        }
                        _SubState = 10;
                        break;

                    case 10:
                        GetToken();
                        _SubState = 11;
                        break;

                    case 11:
                        CheckTagend(_Token);
                        _Entity.IsProcessed = false;
                        Pop();
                        return;
                }
            }
        }