AspNetEdit.Editor.Persistence.AspParser.Parse C# (CSharp) Method

Parse() public method

public Parse ( ) : void
return void
        public void Parse()
        {
            int token;
            string id;
            TagAttributes attributes;
            TagType tagtype = TagType.Text;
            StringBuilder text =  new StringBuilder ();

            while ((token = tokenizer.get_token ()) != Token.EOF) {
                BeginElement ();

                if (tokenizer.Verbatim){
                    string end_verbatim = "</" + verbatimID + ">";
                    string verbatim_text = GetVerbatim (token, end_verbatim);

                    if (verbatim_text == null)
                        OnError ("Unexpected EOF processing " + verbatimID);

                    tokenizer.Verbatim = false;

                    EndElement ();
                    endPosition -= end_verbatim.Length;
                    OnTextParsed (verbatim_text);
                    beginPosition = endPosition;
                    endPosition += end_verbatim.Length;
                    OnTagParsed (TagType.Close, verbatimID, null);
                    continue;
                }

                if (token == '<') {
                    GetTag (out tagtype, out id, out attributes);
                    EndElement ();
                    if (tagtype == TagType.ServerComment)
                        continue;

                    if (tagtype == TagType.Text)
                        OnTextParsed (id);
                    else
                        OnTagParsed (tagtype, id, attributes);

                    continue;
                }

                if (tokenizer.Value.Trim () == "" && tagtype == TagType.Directive) {
                    continue;
                }

                text.Length = 0;
                do {
                    text.Append (tokenizer.Value);
                    token = tokenizer.get_token ();
                } while (token != '<' && token != Token.EOF);

                tokenizer.put_back ();
                EndElement ();
                OnTextParsed (text.ToString ());
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Parses a document fragment. Processes all controls and directives and adds them to host.
        /// </summary>
        /// <param name="fragment">The document fragment to parse</param>
        /// <returns>The document with all controls, directives and script blocks replaced by placeholders</returns>
        public void ProcessFragment(string fragment, out Control[] controls, out string substText)
        {
            AspParser parser = InitialiseParser(fragment);

            rootParsingObject = new RootParsingObject(host);
            openObject        = rootParsingObject;

            parser.Parse();

            if (openObject != rootParsingObject)
            {
                throw new Exception("The tag " + openObject.TagID + " was left unclosed");
            }

            rootParsingObject.GetParsedContent(out controls, out substText);
        }
All Usage Examples Of AspNetEdit.Editor.Persistence.AspParser::Parse