public void TestParseAttributes() { IEnumerator <XmlLightAttribute> en; en = XmlLightParser.ParseAttributes("<tag a=\"1\" b='2' c=3 d e=>").GetEnumerator(); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("a", en.Current.Name); Assert.AreEqual("1", en.Current.Value); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("b", en.Current.Name); Assert.AreEqual("2", en.Current.Value); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("c", en.Current.Name); Assert.AreEqual("3", en.Current.Value); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("d", en.Current.Name); Assert.AreEqual(null, en.Current.Value); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("e", en.Current.Name); Assert.AreEqual("", en.Current.Value); Assert.IsFalse(en.MoveNext()); en = XmlLightParser.ParseAttributes("<?xml version='1.0'?>").GetEnumerator(); Assert.IsTrue(en.MoveNext()); Assert.AreEqual("version", en.Current.Name); Assert.AreEqual("1.0", en.Current.Value); Assert.IsFalse(en.MoveNext()); }
private static void Main() { var output = new StringWriter(); XmlLightParser.Parse(Input, XmlLightParser.AttributeFormat.Html, new OutputFormatter(output)); Console.WriteLine(output.ToString()); }
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); } }
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"]); }
public void TestParseText() { string text = Normalize(XmlLightParser.ParseText(document)); Assert.AreEqual("Document Title this is > cdata! Hi, this is content.", text); }