Example #1
0
        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());
        }
Example #2
0
        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);
            }
        }
Example #3
0
        public void LoadDocument(HtmlMonkeyDocument document)
        {
            tvwNodes.Nodes.Clear();
            TreeNode treeNode = tvwNodes.Nodes.Add("Document");

            treeNode.Tag        = document;
            treeNode.ImageIndex = treeNode.SelectedImageIndex = GetImageIndex(document);
            LoadNodes(document.RootNodes, treeNode);
            tvwNodes.ExpandAll();
            treeNode.EnsureVisible();
        }
Example #4
0
 public frmDetails(object node)
 {
     InitializeComponent();
     Debug.Assert(node != null);
     if (node is HtmlNode)
     {
         Node = node as HtmlNode;
     }
     else if (node is HtmlMonkeyDocument)
     {
         Document = node as HtmlMonkeyDocument;
     }
 }
Example #5
0
        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);
            }
        }
 private static string ShortDescriptionDocument(HtmlMonkeyDocument document) => $"[{document.GetType().ToString()}]";
 private static void PopulatePropertiesDocument(HtmlMonkeyDocument document, ListView listView)
 {
     InitializeListView(DocumentColumns, listView);
     listView.Items.Add("Path").SubItems.Add(document.Path);
 }
 private static string LongDescriptionDocument(HtmlMonkeyDocument document) => string.Empty;
Example #11
0
 public frmVisualizer(HtmlMonkeyDocument document)
 {
     InitializeComponent();
     Document = document;
 }