private void set_url(int num) { string pageText = ""; string url = "/Users/ryanliu/dev/CPEN223/MP1/samples/" + "test" + num + ".html"; pageText = ValidatorMain.ReadCompleteFileOrURL(url); Queue <HtmlTag> tags = new Queue <HtmlTag>(HtmlTag.Tokenize(pageText)); // create the HTML validator this.validator = new HtmlValidator(tags); }
public static void Main() { HtmlValidator validator = new HtmlValidator(); String pageText = ""; String choice = "s"; while (true) { if (choice.StartsWith("s")) { // prompt for page, then download it if it's a URL Console.Write("File name or page URL (blank for empty): "); string url = Console.ReadLine().Trim(); if (url.Length > 0) { if (IsURL(url)) { Console.WriteLine("Downloading from " + url + " ..."); } try { pageText = ReadCompleteFileOrURL(url); Queue <HtmlTag> tags = new Queue <HtmlTag>(HtmlTag.Tokenize(pageText)); // create the HTML validator validator = new HtmlValidator(tags); } catch (UriFormatException) { Console.WriteLine("Badly formatted URL: " + url); } catch (FileNotFoundException) { Console.WriteLine("Web page or file not found: " + url); } catch (IOException ioe) { Console.WriteLine("I/O error: " + ioe.Message); } } else { pageText = "No page text (starting from empty queue)"; validator = new HtmlValidator(); } } else if (choice.StartsWith("a")) { Console.Write("What tag (such as <table> or </p>)? "); string tagText = Console.ReadLine().Trim(); bool isOpenTag = !tagText.Contains("</"); string element = tagText.Replace("[^a-zA-Z!-]+", ""); if (element.Contains("!--")) { element = "!--"; // HTML comments } HtmlTag tag = new HtmlTag(element, isOpenTag); validator.AddTag(tag); } else if (choice.StartsWith("g")) { Console.WriteLine(validator.GetTags()); } else if (choice.StartsWith("p")) { Console.WriteLine(pageText); } else if (choice.StartsWith("r")) { Console.Write("Remove what element? "); String element = Console.ReadLine().Trim(); validator.Remove(element); } else if (choice.StartsWith("v")) { validator.Validate(); Console.WriteLine(); } else if (choice.StartsWith("q")) { break; } Console.WriteLine(); Console.Write("(a)ddTag, (g)etTags, (r)emoveAll, (v)alidate, (s)et URL, (p)rint, (q)uit? "); choice = Console.ReadLine().Trim().ToLower(); } }
public void Init() { this.validator = new HtmlValidator(); }