Re: [Htmlparser-user] Parsing JSP custom tags
Brought to you by:
derrickoswald
From: Somik R. <so...@ya...> - 2003-01-13 05:09:39
|
> I am new to the HTMLParser and was wondering if it can > be used to parse non-HTML tags included in a HTML > file, like JSP custom tags, such as the Struts > <html:...> and <bean:....> tags? Yes. These come in as HTMLTag objects. It is simple to use the parser to pick up tags that you want which are not already covered by the scanners. Here is what a sample program would look like. public class MyApp { MyTagVisitor myTagVisitor = new MyTagVisitor(); public void parse() throws HTMLParserException { HTMLParser parser = HTMLParser.createParser( "<html><html:something><body><bean:some bean tag></body></html>" ); // Replace above with the line below as per your requirements // HTMLParser parser = new HTMLParser("http://www.yahoo.com"); parser.visitAllNodesWith(myTagVisitor); } public List getMyTags() { return myTagVisitor.getMyTags(); } public static void main(String[] args) throws HTMLParserException { MyApp myApp = new MyApp(); myApp.parse(); List myTags = myApp.getMyTags(); HTMLTag tag; for (Iterator i = myTags.iterator();i.hasNext();) { tag = (HTMLTag)i.next(); tag.print(); } } class MyTagVisitor extends HTMLVisitor { List myTags = new ArrayList(); public void visitTag(HTMLTag tag) { if (tag.getText().indexOf("html:")!=-1 || tag.getText().indexOf("bean:")!=-1) myTags.add(tag); } public List getMyTags() { return myTags; } } } |