private static void Main()
    {
        var output = new StringWriter();

        XmlLightParser.Parse(Input, XmlLightParser.AttributeFormat.Html, new OutputFormatter(output));
        Console.WriteLine(output.ToString());
    }
Example #2
0
        public void RunPerfTests()
        {
            string[] files = Directory.GetFiles(@"c:\temp\trash", "*.htm", SearchOption.AllDirectories);
            System.Diagnostics.Stopwatch sw;

            for (int i = 0; i < 10; i++)
            {
                //HTML Parser
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                foreach (string file in files)
                {
                    new HtmlLightDocument(File.ReadAllText(file));
                }

                Console.WriteLine("HTML = {0}", sw.ElapsedMilliseconds);
                //XML Parser
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                foreach (string file in files)
                {
                    new XmlLightDocument(File.ReadAllText(file));
                }

                Console.WriteLine("XHTM = {0}", sw.ElapsedMilliseconds);
                //Parse Only
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                IXmlLightReader rdr = new EmptyReader();
                foreach (string file in files)
                {
                    XmlLightParser.Parse(File.ReadAllText(file), XmlLightParser.AttributeFormat.Xml, rdr);
                }

                Console.WriteLine("NDOM = {0}", sw.ElapsedMilliseconds);
                //Text Only
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                foreach (string file in files)
                {
                    XmlLightParser.ParseText(File.ReadAllText(file));
                }

                Console.WriteLine("TEXT = {0}", sw.ElapsedMilliseconds);
            }
        }
Example #3
0
        public void TestParsers()
        {
            string notxml = "<html id=a ><body foo='bar' bar=\"foo\" />";

            HtmlLightDocument html = new HtmlLightDocument();

            XmlLightParser.Parse(notxml, html);
            Assert.AreEqual("html", html.Root.TagName);
            Assert.AreEqual(1, html.Root.Attributes.Count);
            Assert.AreEqual("a", html.Root.Attributes["id"]);
            Assert.AreEqual(1, html.Root.Children.Count);
            Assert.AreEqual("body", html.Root.Children[0].TagName);
            Assert.AreEqual("foo", html.Root.Children[0].Attributes["bar"]);
            Assert.AreEqual("bar", html.Root.Children[0].Attributes["foo"]);

            XmlLightDocument xml = new XmlLightDocument();

            XmlLightParser.Parse(notxml, XmlLightParser.AttributeFormat.Xml, xml);
            Assert.AreEqual(2, xml.Root.Attributes.Count);
            //Not recognized: xml.Root.Attributes["id"]
            Assert.AreEqual("body", xml.Root.TagName);
            Assert.AreEqual("foo", xml.Root.Attributes["bar"]);
            Assert.AreEqual("bar", xml.Root.Attributes["foo"]);
        }