System.Web.Compilation.AspParser.Parse C# (CSharp) Method

Parse() public method

public Parse ( ) : void
return void
		public void Parse ()
		{
			if (tokenizer == null) {
				OnError ("AspParser not initialized properly.");
				return;
			}
			
			int token;
			string id;
			TagAttributes attributes;
			TagType tagtype = TagType.Text;
			StringBuilder text =  new StringBuilder ();

			try {
				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 ().Length == 0 && 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 ());
				}
			} finally {
				if (fileReader != null) {
					fileReader.Close ();
					fileReader = null;
				}
#if NET_2_0
				checksum = tokenizer.Checksum;
#endif
				tokenizer = null;
			}

#if NET_2_0
			OnParsingComplete ();
#endif
		}

Usage Example

Example #1
0
		void ParseAttributeTag (string code, ILocation location)
		{
			AspParser outerParser = location as AspParser;
			int positionOffset = outerParser != null ? outerParser.BeginPosition : 0;
			AspParser parser = new AspParser ("@@attribute_tag@@", new StringReader (code), location.BeginLine - 1, positionOffset, outerParser);
			parser.Error += new ParseErrorHandler (ParseError);
			parser.TagParsed += new TagParsedHandler (TagParsed);
			parser.TextParsed += new TextParsedHandler (TextParsed);
			parser.Parse ();
			if (text.Length > 0)
				FlushText ();
		}
All Usage Examples Of System.Web.Compilation.AspParser::Parse