示例#1
0
        private void CompileComplexContent(XmlSchemaComplexType complexType, CompiledContentModel compiledContentModel) {
            compiledContentModel.Start();
            XmlSchemaParticle particle = complexType.ContentTypeParticle;
            if (particle != null && compiledContentModel.ContentType != CompiledContentModel.Type.Empty) {
#if DEBUG
                string name = complexType.Name != null ? complexType.Name : string.Empty;
                Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceVerbose, "CompileComplexContent: "+ name  + DumpContentModel(particle));
#endif
                if (particle != XmlSchemaParticle.Empty) {
                    CompileContentModel(compiledContentModel, particle);
                }
            }
            try {
                compiledContentModel.Finish(null, this.compileContentModel);                         
            }
            catch(XmlSchemaException e) {
                e.SetSource(complexType);
                SendValidationEvent(e);
            }
            PushComplexType(complexType);
        }
示例#2
0
        private     void ParseElementDecl() {
            XmlQualifiedName name = XmlQualifiedName.Empty;

            while (true) {
                switch (_SubState) {
                    case 0:
                        _HasSeenWhiteSpace = false;
                        GetToken();
                        name = GetName(_Token, _Namespaces);

                        _ElementDecl = (SchemaElementDecl)_SchemaInfo.ElementDecls[name];
                        if (_ElementDecl != null) {
                            SendValidationEvent(Res.Sch_DupElementDecl, _Scanner.GetText());
                        }
                        else {
                            _ElementDecl = (SchemaElementDecl)_UndeclaredElements[name];
                            if (_ElementDecl != null) {
                                _UndeclaredElements.Remove(name);
                            }
                            else {
                                _ElementDecl = new SchemaElementDecl(name, name.Namespace, SchemaType.DTD, _SchemaNames);
                            }
                            _SchemaInfo.ElementDecls.Add(name, _ElementDecl);
                        }
                        _ElementDecl.IsDeclaredInExternal = !_IsInternal;
                        _SubState = 1;
                        break;

                    case 1:
                        if (!_HasSeenWhiteSpace) {
                            SkipWhitespace(true);
                        }
                        _SubState = 2;
                        break;

                    case 2:
                        GetToken();
                        _ContentModel = _ElementDecl.Content;

                        if (_Token == XmlToken.NAME) {
                            if (_Scanner.IsToken(XmlToken.ANY)) {
                                _ContentModel.ContentType  = CompiledContentModel.Type.Any;
                                _SubState = 12;
                            }
                            else if (_Scanner.IsToken(XmlToken.EMPTY)) {
                                _ContentModel.ContentType  = CompiledContentModel.Type.Empty;
                                _SubState = 12;
                            }
                            else {
                                _SubState = 15; // error;
                            }
                        }
                        else if (_Token == XmlToken.LPAREN) {
                            _ContentModel.Start();
                            _ContentModel.OpenGroup();
                            PushGroup();
                            _SubState = 3;
                            _L = 0;
                            _HasTerminal = false;
                        }
                        else {
                            _SubState = 15; // error
                        }
                        break;

                    case 3:
                        GetToken();
                        if (_Token == XmlToken.HASH) {
                            _SubState = 4;
                        }
                        else {
                            _ContentModel.ContentType  = CompiledContentModel.Type.ElementOnly;
                            _HasTerminal = false;
                            _SubState = 13;
                            Push(DtdFunctionIndex.ParseElementContent);
                            ParseElementContent();
                        }
                        break;

                    case 4:
                        _HasSeenWhiteSpace = SkipWhitespace(false);
                        _SubState = 5;
                        break;

                    case 5:
                        GetToken();
                        if (_HasSeenWhiteSpace || !_Scanner.IsToken(XmlToken.PCDATA))
                            throw new XmlException(Res.Xml_ExpectPcData, _Scanner.StartLineNum, _Scanner.StartLinePos);

                        _ContentModel.AddTerminal( _SchemaNames.QnPCData, null, _InternalValidationEventHandler);
                        _HasTerminal = true;
                        _SubState = 6;
                        break;

                    case 6:
                        _HasSeenWhiteSpace = false;
                        GetToken();
                        if (_Token == XmlToken.RPAREN) {
                            _ContentModel.ContentType  = CompiledContentModel.Type.Text;
                            _ContentModel.CloseGroup();
                            _ContentModel.Finish(_InternalValidationEventHandler, true);
                            PopGroup();
                            _L = -1;
                            _SubState = 14;
                            _HasSeenWhiteSpace = false;
                        }
                        else {
                            _ContentModel.ContentType  = CompiledContentModel.Type.Mixed;
                            _SubState = 7;
                        }
                        break;

                    case 7:
                        if (_Token == XmlToken.OR) {
                            _ContentModel.AddChoice();
                            _HasTerminal = false;
                            _SubState = 8;
                        }
                        else if (_Token == XmlToken.RPAREN) {
                            PopGroup();
                            _L = -1;
                            _HasSeenWhiteSpace = false;
                            _SubState = 10;
                        }
                        else {
                            _SubState = 15; // error
                        }
                        break;

                    case 8:
                        GetToken();
                        _ContentModel.AddTerminal(GetName(_Token, _Namespaces), _Prefix, _InternalValidationEventHandler);
                        _HasTerminal = true;
                        _SubState = 9;
                        break;

                    case 9:
                        _HasSeenWhiteSpace = false;
                        GetToken();
                        _SubState = 7;
                        break;

                    case 10:
                        if (!_HasSeenWhiteSpace) {
                            _HasSeenWhiteSpace = SkipWhitespace(false);
                        }
                        _SubState = 11;
                        break;

                    case 11:
                        GetToken(XmlToken.ASTERISK);
                        if (_HasSeenWhiteSpace)
                            throw new XmlException(Res.Xml_UnexpectedToken, "*", _Scanner.StartLineNum, _Scanner.StartLinePos);
                        _ContentModel.CloseGroup();
                        _ContentModel.Star();
                        _ContentModel.Finish(_InternalValidationEventHandler, true);
                        _SubState = 12;
                        break;

                    case 12:
                        GetToken();
                        _SubState = 13;
                        break;

                    case 13:
                        CheckTagend(_Token);
                        Pop();
                        return;

                    case 14:
                        _HasSeenWhiteSpace = SkipWhitespace(false);
                        GetToken();
                        if (_Token == XmlToken.ASTERISK) {
                            if (_HasSeenWhiteSpace)
                                throw new XmlException(Res.Xml_UnexpectedToken, "*", _Scanner.StartLineNum, _Scanner.StartLinePos);
                            _SubState = 12;
                        }
                        else {
                            _SubState = 13;
                        }
                        break;

                    case 15:
                        throw new XmlException(Res.Xml_InvalidContentModel, _Scanner.StartLineNum, _Scanner.StartLinePos);

                } // switch
            } // while
        }