Package org.htmlparser

Examples of org.htmlparser.Tag


        assertType("firstChild",Text.class,firstChild);
        Node parent = firstChild.getParent();
        assertNotNull("first child parent should not be null",parent);
        assertSame("parent and custom tag should be the same",customTag,parent);

        Tag endTag = (Tag)node[2];
        assertStringEquals(
            "third custom tag html",
            tag3,
            endTag.toHtml()
        );
        assertNull(
            "end tag should have no parent",
            endTag.getParent()
        );

    }
View Full Code Here


    public void testTagExtraction() throws ParserException
    {
        String testHTML = "<AREA \n coords=0,0,52,52 href=\"http://www.yahoo.com/r/c1\" shape=RECT>";
        createParser(testHTML);
        Tag tag = (Tag)parser.elements ().nextNode ();
        assertNotNull(tag);
    }
View Full Code Here

     * @param name Attribute to match in tag
     * @return Tag Tag matching the name attribute
     */
    public Tag searchByName(String name) {
        Node node;
        Tag tag = null;
        boolean found = false;
        for (SimpleNodeIterator e = children();e.hasMoreNodes() && !found;) {
            node = e.nextNode();
            if (node instanceof Tag)
            {
                tag = (Tag)node;
                String nameAttribute = tag.getAttribute("NAME");
                if (nameAttribute!=null && nameAttribute.equals(name))
                    found=true;
            }
        }
        if (found)
View Full Code Here

     * Test constructors.
     */
    public void testConstructors ()
    {
        Vector attributes;
        Tag tag;
        String html;

        attributes = new Vector ();
         // String, null
        attributes.add (new Attribute ("wombat", null));
        // String
        attributes.add (new Attribute (" "));
        // String, String
        attributes.add (new Attribute ("label", "The civil war."));
        attributes.add (new Attribute (" "));
        // String, String, String
        attributes.add (new Attribute ("frameborder", "= ", "no"));
        attributes.add (new Attribute (" "));
        // String String, String, char
        attributes.add (new Attribute ("name", "=", "topFrame", '"'));
        tag = new TagNode (null, 0, 0, attributes);
        html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">";
        assertStringEquals ("tag contents", html, tag.toHtml ());
    }
View Full Code Here

    public void testProperties ()
    {
        Attribute attribute;
        Attribute space;
        Vector attributes;
        Tag tag;
        String html;

        attributes = new Vector ();
        attribute = new Attribute ();
        attribute.setName ("wombat");
        assertTrue ("should be standalone", attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should not be valued", !attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
        attributes.add (attribute);
        space = new Attribute ();
        space.setValue (" ");
        assertTrue ("should not be standalone", !space.isStandAlone ());
        assertTrue ("should be whitespace", space.isWhitespace ());
        assertTrue ("should be valued", space.isValued ());
        assertTrue ("should not be empty", !space.isEmpty ());
        attributes.add (space);
        attribute = new Attribute ();
        attribute.setName ("label");
        attribute.setAssignment ("=");
        attribute.setRawValue ("The civil war.");
        assertTrue ("should not be standalone", !attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should be valued", attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
        attributes.add (attribute);
        attributes.add (space);
        attribute = new Attribute ();
        attribute.setName ("frameborder");
        attribute.setAssignment ("= ");
        attribute.setRawValue ("no");
        attributes.add (attribute);
        attributes.add (space);
        attribute = new Attribute ();
        attribute.setName ("name");
        attribute.setAssignment ("=");
        attribute.setValue ("topFrame");
        attribute.setQuote ('"');
        assertTrue ("should not be standalone", !attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should be valued", attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
        attributes.add (attribute);
        tag = new TagNode (null, 0, 0, attributes);
        html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">";
        assertStringEquals ("tag contents", html, tag.toHtml ());
    }
View Full Code Here

     * Test constructors.
     */
    public void testConstructors2 ()
    {
        Vector attributes;
        Tag tag;
        String html;

        attributes = new Vector ();
         // String, null
        attributes.add (new PageAttribute ("wombat", null));
        // String
        attributes.add (new PageAttribute (" "));
        // String, String
        attributes.add (new PageAttribute ("label", "The civil war."));
        attributes.add (new PageAttribute (" "));
        // String, String, String
        attributes.add (new PageAttribute ("frameborder", "= ", "no"));
        attributes.add (new PageAttribute (" "));
        // String String, String, char
        attributes.add (new PageAttribute ("name", "=", "topFrame", '"'));
        tag = new TagNode (null, 0, 0, attributes);
        html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">";
        assertStringEquals ("tag contents", html, tag.toHtml ());
    }
View Full Code Here

    public void testProperties2 ()
    {
        Attribute attribute;
        Attribute space;
        Vector attributes;
        Tag tag;
        String html;

        attributes = new Vector ();
        attribute = new PageAttribute ();
        attribute.setName ("wombat");
        assertTrue ("should be standalone", attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should not be valued", !attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
        attributes.add (attribute);
        space = new PageAttribute ();
        space.setValue (" ");
        assertTrue ("should not be standalone", !space.isStandAlone ());
        assertTrue ("should be whitespace", space.isWhitespace ());
        assertTrue ("should be valued", space.isValued ());
        assertTrue ("should not be empty", !space.isEmpty ());
        attributes.add (space);
        attribute = new PageAttribute ();
        attribute.setName ("label");
        attribute.setAssignment ("=");
        attribute.setRawValue ("The civil war.");
        assertTrue ("should not be standalone", !attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should be valued", attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
        attributes.add (attribute);
        attributes.add (space);
        attribute = new PageAttribute ();
        attribute.setName ("frameborder");
        attribute.setAssignment ("= ");
        attribute.setRawValue ("no");
        assertTrue ("should not be standalone", !attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should be valued", attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
         attributes.add (attribute);
        attributes.add (space);
        attribute = new PageAttribute ();
        attribute.setName ("name");
        attribute.setAssignment ("=");
        attribute.setValue ("topFrame");
        attribute.setQuote ('"');
        assertTrue ("should not be standalone", !attribute.isStandAlone ());
        assertTrue ("should not be whitespace", !attribute.isWhitespace ());
        assertTrue ("should be valued", attribute.isValued ());
        assertTrue ("should not be empty", !attribute.isEmpty ());
         attributes.add (attribute);
        tag = new TagNode (null, 0, 0, attributes);
        html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">";
        assertStringEquals ("tag contents", html, tag.toHtml ());
    }
View Full Code Here

    {
        String html = "<a>Revision</a>";
        createParser(html,"http://www.yahoo.com");
        parseAndAssertNodeCount(1);
        assertTrue("Node 0 should be a tag",node[0] instanceof Tag);
        Tag tag = (Tag)node[0];
        assertEquals("Tag Contents",html,tag.toHtml());
        assertEquals("Node 0 should have one child", 1, tag.getChildren ().size ());
        assertTrue("The child should be a string node", tag.getChildren ().elementAt (0) instanceof Text);
        Text stringNode = (Text)tag.getChildren ().elementAt (0);
        assertEquals("Text Contents","Revision",stringNode.getText());
    }
View Full Code Here

        assertEquals("Image Height","60",imageTag.getAttribute("HEIGHT"));
        assertEquals("Image Width","468",imageTag.getAttribute("WIDTH"));
        assertEquals("Image Border","0",imageTag.getAttribute("BORDER"));
        assertEquals("Image Alt","See Signs in Theaters 8-2 - Starring Mel Gibson",imageTag.getAttribute("ALT"));
        assertTrue("Second contained node should be Tag",containedNodes[1] instanceof Tag);
        Tag tag1 = (Tag)containedNodes[1];
        assertEquals("Tag Contents","font face=\"verdana,arial,helvetica\" SIZE=\"1\"",tag1.getText());
        assertTrue("Third contained node should be Tag",containedNodes[2] instanceof Tag);
        Tag tag2 = (Tag)containedNodes[2];
        assertEquals("Tag Contents","b",tag2.getText());
        assertTrue("Fourth contained node should be a Tag",containedNodes[3] instanceof Tag);
        Tag tag = (Tag)containedNodes[3];
        assertTrue("Fourth contained node should be an EndTag",tag.isEndTag ());
        assertEquals("Fourth Tag contents","/b",tag.getText());
        assertTrue("Fifth contained node should be a Tag",containedNodes[4] instanceof Tag);
        tag = (Tag)containedNodes[4];
        assertTrue("Fifth contained node should be an EndTag",tag.isEndTag ());
        assertEquals("Fifth Tag contents","/font",tag.getText());

    }
View Full Code Here

     * Check the tag name for one of the ones expected on the page.
     * Recursively check the children.
     */
    public void checkTagNames (Node node)
    {
        Tag tag;
        String name;
        NodeList children;
       
        if (node instanceof Tag)
        {
            tag = (Tag)node;
            name = tag.getTagName ();
            if (!mAcceptable.contains (name))
                fail ("unrecognized tag name \"" + name + "\"");
            children = tag.getChildren ();
            if (null != children)
                for (int i = 0; i < children.size (); i++)
                    checkTagNames (children.elementAt (i));
        }
    }
View Full Code Here

TOP

Related Classes of org.htmlparser.Tag

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.