public void Test() { HtmlMonkeyDocument document = HtmlMonkeyDocument.FromHtml(html); IEnumerable <HtmlElementNode> elements = document.Find("p"); Assert.AreEqual(3, elements.Count()); elements = document.Find("#one-of-many"); Assert.AreEqual(1, elements.Count()); elements = document.Find("p#one-of-many"); Assert.AreEqual(1, elements.Count()); elements = document.Find("p.last-para"); Assert.AreEqual(1, elements.Count()); elements = document.Find("p[data-id=123]"); Assert.AreEqual(3, elements.Count()); elements = document.Find("p[data-id:=\"123\"]"); Assert.AreEqual(3, elements.Count()); elements = document.Find("p[data-id:=\"[0-9]{3}\"]"); Assert.AreEqual(3, elements.Count()); IEnumerable <HtmlCDataNode> cDataNodes = document.FindOfType <HtmlCDataNode>(); Assert.AreEqual(4, cDataNodes.Count()); }
public void Test() { Debug.Assert(NodeData.Length == Markup.Length); for (int i = 0; i < Markup.Length; i++) { HtmlMonkeyDocument document = HtmlMonkeyDocument.FromHtml(Markup[i]); NodeInfo info = NodeData[i]; TestRecursive(info, document.RootNodes); } }
private void parseHTMLToolStripMenuItem_Click(object sender, EventArgs e) { try { Cursor = Cursors.WaitCursor; HtmlMonkeyDocument document = HtmlMonkeyDocument.FromHtml(txtHtml.Text); Cursor = Cursors.Default; frmVisualizer frm = new frmVisualizer(document); frm.ShowDialog(); } catch (Exception ex) { Cursor = Cursors.Default; ex.ShowError(); } }
public void TestXmlHeader() { List <Attribute>[] xmlHeaders = new List <Attribute>[] { new List <Attribute> { new Attribute("version", "1.0") }, new List <Attribute> { new Attribute("version", "1.0"), new Attribute("encoding", "UTF-8"), new Attribute("standalone", "no"), }, }; foreach (List <Attribute> attributes in xmlHeaders) { string header = string.Format($"<?xml {string.Join(" ", attributes)}?>"); HtmlMonkeyDocument document = HtmlMonkeyDocument.FromHtml(header); Assert.AreEqual(1, document.RootNodes.Count); XmlHeaderNode node = document.RootNodes[0] as XmlHeaderNode; Assert.AreNotEqual(null, node); Attribute.CompareAttributes(attributes, node.Attributes); } }
public void TestHtmlHeader() { List <Attribute>[] htmlHeaders = new List <Attribute>[] { new List <Attribute> { new Attribute("html") }, new List <Attribute> { new Attribute("HTML"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD HTML 4.01//EN\""), new Attribute("\"http://www.w3.org/TR/html4/strict.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD HTML 4.01 Transitional//EN\""), new Attribute("\"http://www.w3.org/TR/html4/loose.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD HTML 4.01 Frameset//EN\""), new Attribute("\"http://www.w3.org/TR/html4/frameset.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD XHTML 1.0 Strict//EN\""), new Attribute("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD XHTML 1.0 Transitional//EN\""), new Attribute("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD XHTML 1.0 Frameset//EN\""), new Attribute("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""), }, new List <Attribute> { new Attribute("html"), new Attribute("PUBLIC"), new Attribute("\"-//W3C//DTD XHTML 1.1//EN\""), new Attribute("\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\""), }, }; foreach (List <Attribute> attributes in htmlHeaders) { string header = string.Format($"<!DOCTYPE {string.Join(" ", attributes)}>"); HtmlMonkeyDocument document = HtmlMonkeyDocument.FromHtml(header); Assert.AreEqual(1, document.RootNodes.Count); HtmlHeaderNode node = document.RootNodes[0] as HtmlHeaderNode; Assert.AreNotEqual(null, node); Attribute.CompareAttributes(attributes, node.Attributes); } }