Package org.htmlparser.util

Examples of org.htmlparser.util.NodeIterator


        StringNode snode;
        Node node = null;
        String lin1 =
            "<DIV class=\"userData\" id=\"oLayout\" name=\"oLayout\"></DIV>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                h = tag.getAttributes();
                String classValue = (String) h.get("CLASS");
                assertEquals(
View Full Code Here


        StringNode snode;
        Node node = null;
        String lin1 =
            "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle Kaaila\">Kaarle's homepage</A><p>Paragraph</p>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                href = (String) h.get("HREF");
                myValue = (String) h.get("MYPARAMETER");
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("Link tag (A)", "A", a);
                assertEquals("href value", "http://www.iki.fi/kaila", href);
                assertEquals("myparameter value", "", myValue);
                assertEquals("yourparameter value", "Kaarle Kaaila", nice);
            }
            if (!(node instanceof LinkTag))
            {
                // linkscanner has eaten up this piece
                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    snode = (StringNode) node;
                    assertEquals(
                        "Value of element",
                        snode.getText(),
                        "Kaarle's homepage");
                }

                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    etag = (EndTag) node;
                    assertEquals("endtag of link", etag.getText(), "A");
                }
            }
            // testing rest
            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                assertEquals("following paragraph begins", tag.getText(), "p");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                snode = (StringNode) node;
                assertEquals(
                    "paragraph contents",
                    snode.getText(),
                    "Paragraph");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                etag = (EndTag) node;
                assertEquals("paragrapg endtag", etag.getText(), "p");
            }

        }
View Full Code Here

        StringNode snode;
        Node node = null;
        String lin1 =
            "<G href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaila\">Kaarle's homepage</G><p>Paragraph</p>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                href = (String) h.get("HREF");
                myValue = (String) h.get("MYPARAMETER");
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("The tagname should be G", a, "G");
                assertEquals(
                    "Check the http address",
                    href,
                    "http://www.iki.fi/kaila");
                assertEquals("myValue is empty", myValue, "");
                assertEquals("The second parameter value", nice, "Kaila");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                snode = (StringNode) node;
                assertEquals(
                    "The text of the element",
                    snode.getText(),
                    "Kaarle's homepage");
            }

            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                etag = (EndTag) node;
                assertEquals("Endtag is G", etag.getText(), "G");
            }
            // testing rest
            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                assertEquals("Follow up by p-tag", tag.getText(), "p");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                snode = (StringNode) node;
                assertEquals(
                    "Verify the paragraph text",
                    snode.getText(),
                    "Paragraph");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                etag = (EndTag) node;
                assertEquals("Still patragraph endtag", etag.getText(), "p");
            }

        }
View Full Code Here

        EndTag etag;
        StringNode snode;
        Node node = null;
        String lin1 = "<A yourParameter = \"Kaarle\">Kaarle's homepage</A>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

            if (en.hasMoreNodes())
            {
                node = en.nextNode();

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("Link tag (A)", a, "A");
                assertEquals("yourParameter value", "Kaarle", nice);
            }
            if (!(node instanceof LinkTag))
            {
                // linkscanner has eaten up this piece
                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    snode = (StringNode) node;
                    assertEquals(
                        "Value of element",
                        snode.getText(),
                        "Kaarle's homepage");
                }

                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    etag = (EndTag) node;
                    assertEquals(
                        "Still patragraph endtag",
                        etag.getText(),
                        "A");
View Full Code Here

        StringNode snode;
        Node node = null;
        String testHTML =
            "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle\">Kaarle's homepage</A><p>Paragraph</p>";
        createParser(testHTML);
        NodeIterator en = parser.elements();
        String result = "";
        try
        {
            while (en.hasMoreNodes())
            {
                node = en.nextNode();
                result += node.toHtml();
            }
            String expected =
                "<A YOURPARAMETER=\"Kaarle\" MYPARAMETER=\"\" HREF=\"http://www.iki.fi/kaila\">Kaarle's homepage</A><P>Paragraph</P>";
            assertStringEquals(
View Full Code Here

        Node node = null;
        String testHTML =
            "<INPUT name=\"foo\" value=\"foobar\" type=\"text\" />";

        createParser(testHTML);
        NodeIterator en = parser.elements();
        String result = "";
        try
        {
            while (en.hasMoreNodes())
            {
                node = en.nextNode();
                result = node.toHtml();
            }
            String expected =
                "<INPUT VALUE=\"foobar\" NAME=\"foo\" TYPE=\"text\"/>";
            assertStringEquals(
View Full Code Here

    public void testExtractXMLData() throws ParserException
    {
        createParser("<MESSAGE>\n" + "Abhi\n" + "Sri\n" + "</MESSAGE>");
        Parser.setLineSeparator("\r\n");
        NodeIterator e = parser.elements();

        Node node = e.nextNode();
        try
        {
            String result =
                TagScanner.extractXMLData(node, "MESSAGE", parser.getReader());
            assertEquals("Result", "Abhi\r\nSri\r\n", result);
        }
        catch (ParserException ex)
        {
            assertTrue(e.toString(), false);
        }
    }
View Full Code Here

    }

    public void testExtractXMLDataSingle() throws ParserException
    {
        createParser("<MESSAGE>Test</MESSAGE>");
        NodeIterator e = parser.elements();

        Node node = (Node) e.nextNode();
        try
        {
            String result =
                TagScanner.extractXMLData(node, "MESSAGE", parser.getReader());
            assertEquals("Result", "Test", result);
        }
        catch (ParserException ex)
        {
            assertTrue(e.toString(), false);
        }
    }
View Full Code Here

     */
    public void testIsXMLTag() throws ParserException
    {
        createParser("<OPTION value=\"#\">Select a destination</OPTION>");
        Node node;
        NodeIterator e = parser.elements();
        node = (Node) e.nextNode();
        assertTrue(
            "OPTION tag could not be identified",
            TagScanner.isXMLTagFound(node, "OPTION"));
    }
View Full Code Here

        assertEquals("Body", "BODY: Yahoo!", bodyTag.toString());
    }

    public void testAttributes()
    {
        NodeIterator iterator;
        Node node;
        Hashtable attributes;

        try
        {
            createParser("<body style=\"margin-top:4px; margin-left:20px;\" title=\"body\">");
            parser.addScanner(new BodyScanner("-b"));
            iterator = parser.elements();
            node = null;
            while (iterator.hasMoreNodes())
            {
                node = iterator.nextNode();
                if (node instanceof BodyTag)
                {
                    attributes = ((BodyTag) node).getAttributes();
                    assertTrue(
                        "no style attribute",
                        attributes.containsKey("STYLE"));
                    assertTrue(
                        "no title attribute",
                        attributes.containsKey("TITLE"));
                }
                else
                    fail("not a body tag");
                assertTrue("more than one node", !iterator.hasMoreNodes());
            }
            assertNotNull("no elements", node);
        }
        catch (ParserException pe)
        {
View Full Code Here

TOP

Related Classes of org.htmlparser.util.NodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.