Exemplo n.º 1
0
        public void TestFormNodeShouldBeNode()
        {
            JsonizeConfiguration jsonizeConfiguration = new JsonizeConfiguration();

            Jsonize jsonize = new Jsonize("<html><head></head><body><form></form></body></html>");
            var     result  = jsonize.ParseHtmlAsJsonString(jsonizeConfiguration);

            Assert.AreEqual("{\"node\":\"Document\",\"child\":[{\"node\":\"Element\",\"tag\":\"html\",\"child\":[{\"node\":\"Element\",\"tag\":\"head\"},{\"node\":\"Element\",\"tag\":\"body\",\"child\":[{\"node\":\"Element\",\"tag\":\"form\"}]}]}]}",
                            result.Replace("\r\n", "").Replace(" ", ""));
        }
Exemplo n.º 2
0
        public void TestEmptyTextNodesHandlingIgnore()
        {
            JsonizeConfiguration jsonizeConfiguration = new JsonizeConfiguration
            {
                EmptyTextNodeHandling = EmptyTextNodeHandling.Ignore
            };

            string  html    = "<html><head></head><body><form></form><p></p></body></html>";
            Jsonize jsonize = new Jsonize(html);
            string  result  = jsonize.ParseHtmlAsJsonString(jsonizeConfiguration);

            Assert.AreEqual("{\"node\":\"Document\",\"child\":[{\"node\":\"Element\",\"tag\":\"html\",\"child\":[{\"node\":\"Element\",\"tag\":\"head\"},{\"node\":\"Element\",\"tag\":\"body\",\"child\":[{\"node\":\"Element\",\"tag\":\"form\"},{\"node\":\"Element\",\"tag\":\"p\"}]}]}]}",
                            result.Replace("\r\n", "").Replace(" ", ""));
        }
Exemplo n.º 3
0
        private static async Task <string> TestJsonizeAsString(JsonizeConfiguration jsonizeConfiguration)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                string url = @"http://jackfinlay.com";

                HttpResponseMessage response = await client.GetAsync(url);

                string html = await response.Content.ReadAsStringAsync();

                Jsonize jsonize = new Jsonize(html);

                return(jsonize.ParseHtmlAsJsonString(jsonizeConfiguration));
            }
        }
Exemplo n.º 4
0
        private static async Task <string> TestJsonizeAsString()
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                string url = @"http://jackfinlay.com";

                HttpResponseMessage response = await client.GetAsync(url);

                string html = await response.Content.ReadAsStringAsync();

                //html = System.IO.File.ReadAllText(@"C:\Users\Public\file.html");
                Jsonize jsonize = new Jsonize(html);
                jsonize.ShowEmptyTextNodes(false);

                return(jsonize.ParseHtmlAsJsonString());
            }
        }