PhpWiki - Custom Tag Extraction
Keywords: Custom Tag Extraction, PhpWiki

Custom Tag Extraction

Custom tag extraction is easy. Simply create an array of tag names that you want to extract from a page, and pass it in to a TagFindingVisitor, like so:

    import org.htmlparser.Node;
    import org.htmlparser.Parser;
    import org.htmlparser.util.ParserException;
    import org.htmlparser.visitors.TagFindingVisitor;

    public class CustomTagDemo
    {
        public static void main (String[] args) throws ParserException
        {
            Parser parser = new Parser ("http://urlIWantToParse.com");
            String [] tagsToBeFound = {"P","BR","MYTAG"};
            TagFindingVisitor visitor = new TagFindingVisitor (tagsToBeFound);
            parser.visitAllNodesWith (visitor);
            // First tag specified in search
            Node [] allPTags = visitor.getTags(0);
            // Second tag specified in search
            Node [] allBRTags = visitor.getTags(1);
            // Third tag specified in search
            Node [] allMyTags = visitor.getTags(2);
        }
    }

| Page Execution took 0.213 seconds